[英]execute python programme in loop through windows command prompt
So I have a python programme which looks something like this:所以我有一个看起来像这样的python程序:
import blah blah balh
def main():
blah blah blah
blah blah blah
if __name__ == "__main__":
main()
The programme takes 2 arguments via eclipse.该程序通过 eclipse 接受 2 个参数。
But now I would like to run this programme in windows control prompt in a loop and change the 2 arguments dynamically.但是现在我想在 Windows 控制提示中循环运行该程序并动态更改 2 个参数。
I would like to do something like this:我想做这样的事情:
arg1 = [a,b,c,d]
arg2 = [a,b,c,d]
for idx in range(0, len(mtds)):
#pass in args to programme
programme(mtds[idx], mdd[idx])
Is this possible?这可能吗?
Apologies in advance, I'm totally ignorant about this.提前道歉,我对此一无所知。
Here is how you loop in CMD:这是在 CMD 中循环的方式:
for /l %x in (1, 1, 100) do (
echo %x Prints the current iteration
python myPythonscript.py input1 input2
)
Starts at 1, steps by 1 and ends at 100.从 1 开始,步长 1,到 100 结束。
If you want to loop your programm's main()
function for a certain amount of times with 2 arguments then you can add some strings:如果要使用 2 个参数循环程序的
main()
函数一定次数,则可以添加一些字符串:
import sys
first_arg = sys.argv[1]
second_arg = sys.argv[2]
times_to_loop = sys.argv[3]
import blah blah balh
def main():
blah blah blah
blah blah blah
for i in range(int(times_to_loop)):
main(first_argv, second_argv)
and run your programm from cmd
as python programm.py 1 2 10
.并从
cmd
运行您的程序作为python programm.py 1 2 10
。
This will run your programm 10 times with 1
as first argument and 2
as second这将运行PROGRAMM 10次
1
作为第一个参数, 2
为第二
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.