简单的Python代码在Zapier Code函数中不起作用

问题描述 投票:1回答:1

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

该程序的目标是确定某件商品是否包含电话号码,电子邮件或同时包含两者。有什么想法吗?我对Zapier的Python和代码相当陌生,所以我敢肯定这很简单。

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代码

enter image description here

python python-3.x zapier
1个回答
1
投票

即使值是空的

您的代码正在专门检查空字符串,而不是null(无)。所以是的,如果项目为空,则将两者都说。尝试进行“真实的”检查,而不要专门检查空字符串。

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}]
© www.soinside.com 2019 - 2024. All rights reserved.