【问题标题】:I can't get an output in my python code in Zapier我无法在 Zapier 的 python 代码中获得输出
【发布时间】:2020-02-09 11:00:37
【问题描述】:

我一直在使用 python 阅读 Zapier 文档,他们展示了这个例子:

output= {'has_lunch': False}

if input.get('body') and 'lunch' in input['body']:
        output['has_lunch'] = True

实际上这看起来像是我正在寻找的东西,示例和我的代码之间的主要区别在于我想传递多个参数并评估这些参数以获取特定的输出。

例如:

output= {'Mango': 1, 'Apple': 2}

if input.get('Fruits') and 'Mango' in input['Fruits']:
        output['Mango'] =  1
elif input.get('Fruits') and 'Apple' in input['Fruits']:
        output['Apple'] =  2

错误:输出丢失请定义输出或提前返回。

【问题讨论】:

  • 总是将完整的错误消息(从单词“Traceback”开始)作为文本(不是屏幕截图)放在有问题的(不是评论)中。还有其他有用的信息。

标签: python zapier


【解决方案1】:

我认为这是你需要的:

if input.get('Fruits') and 'Mango' in input['Fruits']:
        mango = 1
else: mango = None

if input.get('Fruits') and 'Apple' in input['Fruits']:
        apple = 2
else: apple = None       
output = {'mango': mango, 'apple': apple}

由于 zapier 的设置方式,它显示为 Error: output missing Please define output or return early。在 JS 中,您可以执行 output 或执行 if/else 并执行 return。我不是 Python 方面的专家,但您需要在 JS 中使用等效于 return 的代码才能工作,否则它将在到达第一个 output 时停止该函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    相关资源
    最近更新 更多