如何解决我正在尝试将不同的参数传递给每个计划的函数,如下所示,
import schedule
import time
arr = ['React','Python','JS','PHP','anything']
def add_no(key):
return print(key,' got it')
for i,index in enumerate(arr):
schedule.every(3).seconds.do(add_no,index)
schedule.run_pending()
time.sleep(2)
print(i,':',index)
我正在尝试将不同的参数传递给每个计划的函数,如下所示: 每个指定的时间段我想从 arr 传递一个参数并执行代码,然后完成后,我将第二个传递给函数,依此类推直到循环退出,就像每 3 分钟我想将 str 作为 arg 传递给my function 和 make execution 等等:现在终端显示,
0: React
1: Python
React got it
2: JS
Python got it
3: PHP
React got it
JS got it
4: anything
我想要的输出是
0: React
React got it
1: Python
Python got it
2: JS
JS got it
3: PHP
PHP got it
JS got it
等等
解决方法
也许你想要这样的东西
import schedule
import time
arr = ['React','Python','JS','PHP','anything']
def add_no(key):
return print(key,' got it')
for i,index in enumerate(arr):
schedule.every(3).seconds.do(add_no,index)
schedule.run_pending()
time.sleep(3)
print(i,':',index)
0 : React
React got it
1 : Python
Python got it
React got it
2 : JS
JS got it
Python got it
React got it
3 : PHP
PHP got it
JS got it
Python got it
React got it
4 : anything
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。