我关注了Python的Zapier代码文档,但我仍然遇到这个问题:
目的:
我正在尝试从Acuity Scheduling重新格式化我的输入(Feets)并在Salesforce上更新它。
代码:
if " ' " in input_data['Feets']:
output = {'Feets':Feets.split("'")[0],'Inches':Feets.split("'")[1]}
else
output = {'Feets':Feets,'Inches':Inches}
输出:
更新
我更新了代码,但现在我无法在后面的步骤中获得输出。
输入:
if "'" in input_data['Feets']:
output = {'Feets': input_data['Feets'].split("'")[0],'Inches':input_data['Feets'].split("'")[1]}
elif "," in input_data['Feets']:
output = {'Feets': input_data['Feets'].split(",")[0],'Inches':input_data['Feets'].split(",")[1]}
else:
output = {'Feets': input_data['Feets'],'Inches': input_data['Inches']}
错误讯息:
追踪(最近一次通话): 在the_function中输入“/tmp/tmpMwZDgy/usercode.py”,第8行 如果input_data中有“'”['Feets']: KeyError:'Feets'
答案 0 :(得分:1)
David来自Zapier平台团队。你有两个问题:
:
,导致python无法正确解析"'"
input_data
dict 以下代码按预期工作:
if "'" in input_data['Feets']:
output = {'Feets': input_data['Feets'].split("'")[0], 'Inches': input_data['Feets'].split("'")[1]}
else:
output = {'Feets': input_data['Feets'],'Inches': input_data['Inches']}