python - 我正在尝试将不同的参数传递给每个时间表的函数,如下所示,
问题描述
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 传递给我的函数并执行等等:现在终端显示,
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
推荐阅读
- typo3 - Typo 3 v9 - 路由增强器
- python - 带有漂亮汤的 Python 自定义 nagios 脚本 - 获取“NRPE:无法读取输出”
- solr - Solr按每个单词的开头搜索
- javascript - 寻找一种基于另一个项目的 ID 来选择类的方法
- android - Android 自定义 lint 规则未检测到任何问题(对于导入)
- javascript - 函数和箭头 (=>) 函数之间有区别吗
- linux - 如何为 .sh 文件制作 .desktop 文件
- cassandra - 在 Cassandra 中插入多次后出现无效或不支持的协议版本错误
- excel - 尝试根据数据移动整行
- java - JSP 导入中的上下文路径