【发布时间】:2017-05-20 13:08:00
【问题描述】:
所以我想使用 Python 调用一个 shell 脚本
from subprocess import call
在位于不同目录的一组具有相同扩展名的文件上。这是我目前所拥有的:
for path, subdirs, files in os.walk(dir_path):
for name in files:
if name.endswith(".avg"):
os.chdir(os.path.join(path))
call("shell_script *avg", shell=True)
print("creating new file for... " + name)
但它只是一遍又一遍地循环遍历同一组文件,最终在大约 5 次迭代之后,它会移动到下一组文件并执行相同的操作。我只是发现了这一点,因为我正在查看内核并看到它一遍又一遍地在相同的文件上执行相同的 shell 脚本。我在哪里错了?
【问题讨论】:
标签: shell python-3.x subprocess