脚本很简单:
import datetime
import json
today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
if 15 <= next_thursday.day <= 21:
next_third_thursday = next_thursday
break
else:
next_date = next_thursday + datetime.timedelta(days=1)
next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))
return json.dumps({'date': str(next_third_thursday)})
如何运行此代码?这里有什么问题吗?
最佳答案
Zapier 期望脚本的输出是一个 JSON 可序列化的对象(来自评论部分的 Michael Case 的 h/t)。
此外,脚本没有正确缩进。 Python 是一种对缩进敏感的语言,即缩进很重要。
尝试这样的事情:
import datetime
today = datetime.date.today()
next_thursday = today + datetime.timedelta(((3 - today.weekday()) % 7))
while True:
if 15 <= next_thursday.day <= 21:
next_third_thursday = next_thursday
break
else:
next_date = next_thursday + datetime.timedelta(days=1)
next_thursday = next_date + datetime.timedelta(((3 - next_date.weekday()) % 7))
return {'date': str(next_third_thursday)}
关于python - Zapier 给出错误 : `' unicode' object has no attribute 'copy' ` for Python script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54277462/