繁体   English   中英

如何多次运行python代码

[英]How to run a python code more than once

我试图通过将 num_runs 设置为 3 来运行这个 python 代码,而不是使用它。它只能正确运行一次。 它运行了两次,但只有第一个文件中有数据。

import random
from math import sqrt
import subprocess
import time

# Set clock
START=time.clock()

# Simulation Parameters - num_real_runs is needed to set the range command in python
num_runs=3

# Counter Variable for total numbers of runs
running=1

while (running<num_runs):   

    # Execute mcell Part1
    subprocess.call("mcell -seed "+str(running)+" Scene.main_1.mdl", shell=True)

    # Execute mcell Part2
    subprocess.call("mcell -seed "+str(running)+" Scene.main_2.mdl", shell=True)

    # Calculate elapsed time for executing python script only (in min)
    END=time.clock()
    ELAPSED=(END-START)
    print "Man, it took me only", ELAPSED, "seconds to run the python code!"    
    running+=1

它只运行两次,因为在第三次循环时,3 不小于 3。将while语句更改为:

while (running<=num_runs): 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM