如何正确 return Zapier Code (Python) 中的字典列表?
How to correctly return a list of dictionaries in Zapier Code (Python)?
Zapier 代码文档说代码 zap 的输出可以是字典或字典列表(参见 "Data Variable" 部分:https://zapier.com/help/code-python/)。
执行此操作时,
output = [{'Booking':'Shirt'},{'Booking':'Jeans'}]
代码的输出returns只有第一个字典,然而:
runtime_meta__duration_ms: 2
runtime_meta__memory_used_mb: 22
id: [redacted]
Booking: Shirt
Fields with no value:
runtime_meta__logs
我在这里做错了什么?非常感谢!
这里是来自 Zapier 平台团队的 David。返回数组的代码步骤大部分是未记录的(因为没有 UI 支持,而且它很混乱,正如您所知)功能。
测试时,它只会显示数组中的第一项。当它真正 运行 时,代码步骤之后的所有步骤都将为数组中的每个项目 运行 。任务历史记录将反映此
所以设置 zap 并打开,它会像您预期的那样工作。
抱歉给您带来了困惑,如果您有任何其他问题,请告诉我!
对于仍在寻找此问题答案的任何人,以下是在 Zapier 中查找返回列表的内容。
# first import and convert your input value to an array.
# special note any line items imported into a python variable are converted to list format.
my_items = input_data['my_CSV_string']
my_list_of_items = my_items.split(",")
# Create a new list array
my_new_list = []
length = len(my_list_of_items)
#Do all your computations
for i in range(length):
my_new_list.append(float(my_list_of_items[i])*1.5)
# After completing any tasks you can return the list as follows,
# If you are using line items keep the list in its original format
return {
'my_processed_values': my_new_list,
'original_values': my_list_of_items
}
# If you want to return it as a CSV "basically making the array flat"
my_old_CSV_list= ','.join(map(str, my_list_of_items))
my_new_CSV_list= ','.join(map(str, my_new_list))
return {
'my_processed_cvs_values': my_new_CSV_list,
'original_values': my_list_of_items
}
希望这对您有所帮助。我不是 Python 专家,但理论上使用的列表越多,zap 处理的时间就越长。尽量将您的 python 处理时间保持在最低水平。
最佳,
Zapier 代码文档说代码 zap 的输出可以是字典或字典列表(参见 "Data Variable" 部分:https://zapier.com/help/code-python/)。
执行此操作时,
output = [{'Booking':'Shirt'},{'Booking':'Jeans'}]
代码的输出returns只有第一个字典,然而:
runtime_meta__duration_ms: 2
runtime_meta__memory_used_mb: 22
id: [redacted]
Booking: Shirt
Fields with no value:
runtime_meta__logs
我在这里做错了什么?非常感谢!
这里是来自 Zapier 平台团队的 David。返回数组的代码步骤大部分是未记录的(因为没有 UI 支持,而且它很混乱,正如您所知)功能。
测试时,它只会显示数组中的第一项。当它真正 运行 时,代码步骤之后的所有步骤都将为数组中的每个项目 运行 。任务历史记录将反映此
所以设置 zap 并打开,它会像您预期的那样工作。
抱歉给您带来了困惑,如果您有任何其他问题,请告诉我!
对于仍在寻找此问题答案的任何人,以下是在 Zapier 中查找返回列表的内容。
# first import and convert your input value to an array.
# special note any line items imported into a python variable are converted to list format.
my_items = input_data['my_CSV_string']
my_list_of_items = my_items.split(",")
# Create a new list array
my_new_list = []
length = len(my_list_of_items)
#Do all your computations
for i in range(length):
my_new_list.append(float(my_list_of_items[i])*1.5)
# After completing any tasks you can return the list as follows,
# If you are using line items keep the list in its original format
return {
'my_processed_values': my_new_list,
'original_values': my_list_of_items
}
# If you want to return it as a CSV "basically making the array flat"
my_old_CSV_list= ','.join(map(str, my_list_of_items))
my_new_CSV_list= ','.join(map(str, my_new_list))
return {
'my_processed_cvs_values': my_new_CSV_list,
'original_values': my_list_of_items
}
希望这对您有所帮助。我不是 Python 专家,但理论上使用的列表越多,zap 处理的时间就越长。尽量将您的 python 处理时间保持在最低水平。
最佳,