有人可以帮助我理解如何将多个列表中的值作为函数参数传递吗?我正在尝试使用包含customerId的url更新每个myemailId的电子邮件。
到目前为止,我的代码:
emailId = [732853380,7331635674]
customerId = ['cust-12345-mer','cust-6789-mer']
for x, y in zip(emailId, customerId):
def update_email(emailId, token, user, notes="https://myurl.com/customer?customerId =" + customerId):
headers = { 'accept': 'application/json',
'Content-Type': 'application/json',
'token': token,
'user': user}
endpoint = 'email/'
body = {'emailId': emailId, 'user': user, 'notes': notes}
requests.put(url = host + endpoint, headers = headers, json=body)
return True
但收到与以def update_email
...开头的行相对应的错误:
TypeError: must be str, not list
提前致谢!
首先,您不应该为每次循环迭代定义函数,而应该在执行循环之前定义一次。
为了传递值,请使用:
emailId = [732853380, 7331635674]
customerId = ['cust-12345-mer', 'cust-6789-mer']
def update_email(emailId, token, user, customerId):
notes = "https://myurl.com/customer?customerId =" + customerId
headers = {'accept': 'application/json',
'Content-Type': 'application/json',
'token': token,
'user': user}
endpoint = 'email/'
body = {'emailId': emailId, 'user': user, 'notes': notes}
requests.put(url=host + endpoint, headers=headers, json=body)
return True
for x, y in zip(emailId, customerId):
update_email(x, token, user, y)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句