【问题标题】:Simple Python Code not working in Zapier Code function简单的 Python 代码在 Zapier 代码功能中不起作用
【发布时间】:2020-01-04 21:51:48
【问题描述】:

我在Zapier 应用程序中的代码有问题。我写了一个相当简单的if, elif,但我绘制的输出不正确。如果我将变量声明为or,则代码可以工作,但是当使用input.get(这是一个要求)时,即使值是null,代码也会始终回答这两个问题。

该程序的目标是确定一个项目是否有电话号码、电子邮件或两者都有。有什么想法吗?我对 Python 和 Zapier 的代码相当陌生,所以我相信这很简单。

phoneTest = input.get('Phone')
emailTest = input.get('Email')

if(emailTest != '') and (phoneTest != ''):
    logic = 'both'
elif(emailTest == '') and (phoneTest != ''):
    logic = 'phone'
elif(emailTest != '') and (phoneTest == ''):
    logic = 'email'

output = [{'test': emailTest}]

Zapier 中的 Python 代码

【问题讨论】:

    标签: python python-3.x zapier


    【解决方案1】:

    即使值为空

    您的代码专门针对空字符串进行检查,而不是 null (None)。所以是的,如果项目为空,它会说两者。尝试进行“真实”检查,而不是专门检查空字符串。

    phoneTest = input.get('Phone')
    emailTest = input.get('Email') 
    
    if emailTest and phoneTest: 
        logic = 'both'
    elif phoneTest: 
        logic = 'phone'
    elif emailTest: 
        logic = 'email'
    
     output = [{'test': emailTest, 'logic': logic}]
    

    【讨论】:

    • 谢谢@Nick Humrich
    猜你喜欢
    • 2018-03-10
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多