-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