-1
我想調用一個子程序來收集數據。這是一個循環。因此,我想寫入一個excel文件的每個迭代。我可以將子程序複製到主程序中,但想要更簡潔的方法來執行此操作。我有這樣的事情:Python - 將子程序變量傳遞給主程序
#This creates my path and file name to open later
path = os.getcwd()
filetime = time.strftime("_%Y_%H_%M_%S", time.localtime())
fname = 'Test'
fext = '.csv'
fpath = path + '/' + fname + filetime + fext
#start of loop
for val1 in range(5):
for val in range(6):
#write some register with val1
#write some register with val2
subprocess.call("test.py", shell=True)
#this subprosses does something that spits out data for 8 variables a through h
#I would like to write that data into the path and file I created above
data=open(fpath, 'a')
#data.write('%.2f\n' % (cl))
data.write('%i,%i,%i,%.2f,%.2f,%.2f,%.2f,%.2f\n' % (a,b,c,d,e,f,g,h))
data.close()
你爲什麼不把它整合到一個程序中?從python調用python進程是毫無意義的。 – Darek
我不明白。你想看看「進口」? – User