我可以帮您将以下内容翻译为中文:
发生了什么: 显然,subprocess模块对从my_module.run()返回的THAT进行了一些处理,导致了崩溃:
如果THAT = list_of_lists,则会出现错误:
我想要获取从主程序调用的模块函数的stdout、stderr和resultcode。我以为subprocess是关键,但我没有成功地将模块函数提交到subprocess。
我现在拥有的:
#my_module.py
def run(args):
do stuff
print this
return THAT
if name == "__main__":
args = read_args()
run(args)
.
#my_main_script.py
import subprocess as sp
import my_module
p = sp.Popen(my_module.run(args), stdout=sp.PIPE, stderr=sp.PIPE)
out, err = p.communicate()
result = p.resultcode
发生了什么: 显然,subprocess模块对从my_module.run()返回的THAT进行了一些处理,导致了崩溃:
如果THAT = list_of_lists,则会出现错误:
AttributeError: "sublist" object has no attribute rfind
如果THAT = ["a","b",0],则会出现错误:TypeError: execv() arg 2 must contain only strings
;如果THAT = ["a","b"],则会出现错误:OSError: [Errno 2] No such file or directory
因此,subprocess显然希望将THAT作为包含文件路径的列表?