【发布时间】:2020-08-23 04:08:48
【问题描述】:
我编写了一个函数,它读取并运行 python 脚本,然后将其输出发送到文本文件。 如果它运行的脚本损坏/不起作用,我试图让它向文本文件写入一个简单的字符串或有问题的错误。 以下是有问题的代码:
file_dir = a_dir[0]
file_name = a_dir[1][:-3]
with open(f'{self.output_directory}\\output_{file_name}.txt', 'w') as f:
try:
subprocess.call(
[sys.executable, file_dir], stdout=f)
except:
f.write("An error occured with the script")
它的第一部分工作正常 - 它确实运行一个正常运行的文件并写入输出。
我需要更具体地说明错误异常吗?任何帮助将不胜感激!
【问题讨论】: