如何在for循环调用Shell脚本中转​​义Python名称错误?

时间:2017-04-19 10:42:24

标签: python linux shell

 def startdataprocessing (self, widget):
    text_file = open("SRAIdFromPythonInput.txt", "w")
for item in text_file:
    execute('bash ./oneclickdataprocessor.sh')
text_file.close()

我有错误text_file未定义。如何解决?在.txt文件中的每个项目上调用.sh脚本是否正确,或者我应该使用Linux shell嵌入for循环?

1 个答案:

答案 0 :(得分:0)

就你的剧本而言

text_file = open("SRAIdFromPythonInput.txt", "w")
for item in text_file:
    execute('bash ./oneclickdataprocessor.sh')
text_file.close()

要调用外部shell文件,请考虑subprocess模块。更多this question