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

2024-09-29 21:45:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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代码:

enter image description here


Tags: orand代码应用程序声明inputgetif
1条回答
网友
1楼 · 发布于 2024-09-29 21:45:25

even if the values are null

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

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}]

相关问题 更多 >

    热门问题