簡體   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