x = open('data.txt', 'a')
g = open('graphing_data.txt', 'a')
subprocess.call(['sfit4Layer0.py', '-bv5', '-fh']) # only need to do this once
with open('filenames.txt', 'r') as r:
for line in r:
opusfile = line.strip()
subprocess.call(['ckopus', '-FSNGC', '-SFL0', '-u6', opusfile])
subprocess.call(['sfit4Layer0.py', '-bv5', '-fp'])
subprocess.call(['sfit4Layer0.py', '-bv5', '-fs'])
# now summary file is produced so must write in summary file code here
for infile in glob.glob(os.path.join(road, 'summary*')):
#write data from summary to data.txt and graphing_data.txt
x.close()
g.close()
我有一个程序需要将上面subprocess.call
行中找到的命令写入终端来处理数据文件,所以我想我会编写一个程序来自动执行此操作(我有超过100个数据文件) )。我的程序使用文件名列表引用filenames.txt,并将其作为opusfile读取,以使用第一个命令执行。它似乎正确处理第一个文件,然后我收到此错误:
Traceback (most recent call last):
File "template.py", line 24, in <module>
subprocess.call(['ckopus', '-FSNGC', '-SFL0', '-u6', opusfile])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我已经尝试过了解子进程模块,但是对我来说有点困惑,如果有人有提示或链接到一个很棒的实用教程 - 我在Python上相当新。