我有许多 python 脚本,我想通过管道传输大约 1000 次,并更改每个脚本的输入文件
我之前使用 bash shell 脚本执行此操作,但现在我需要它在 Windows 计算机上工作。
这是Python,有问题的行已被注释掉
namecount = 0
for file in files:
in_filestring = "test_" + str(namecount)
out_filestring = "out_ + str(namecount)
namecount += 1
#Run this on the command line: python pre.py < in_filestring | filter.py | a_filter.py > out_filestring
我可以在这里使用这个还是有更好的方法?我问是因为我目前正在阅读 subprocess http://docs.python.org/2/library/subprocess.html 。显然它取代了过时的 os.system,但我还不明白如何使用它。
import os
os.system('system command you want to run')
最佳答案
subprocess.call 应该没问题。基本的是,
call(["args" in comma separated])
这是链接http://docs.python.org/2/library/subprocess.html#using-the-subprocess-module .
就你的情况而言,尝试这样的事情,
from subprocess import call
...
...
call(["python", "pre.py", "<", filestring, "|", "filter.py", "|", "a_filter.py", ">", "out_filestring"])
关于python - 使用python批量运行其他python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17377113/