2017-01-25 46 views
-1

我試圖通過num_runs設置爲3到運行此Python代碼比使用越來越它只正確運行一次。它運行兩次,但只有第一個文件有數據。如何運行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

必須來自您的MCELL命令....嘗試要手動運行它們,你可能會遇到同樣的問題。 –

回答

1

它只能運行兩次,因爲通過循環第三次,3不小於3.更改少while聲明:

while (running<=num_runs):