【发布时间】:2019-07-05 10:10:27
【问题描述】:
我有一个 python 脚本“script1.py”,它在执行结束时创建一个字典“out_dict”。我正在从另一个脚本“script2.py”调用“script1.py”。
有没有办法只将最终字典“out_dict”(注意:我在“scirpt1.py”中也有一些打印语句)放入“script2.py”中的变量中。
script1.py
......
......
some print statement
......
some print statement
......
out_dict = {...}
print(out_dict)
script2.py
import os
val = os.system("python3.6 script1.py")
【问题讨论】:
-
你能打印输出吗?
-
您可以在
print(out_dict)之前插入print("MARKER")之类的内容,然后在此标记字符串上拆分val,并仅使用拆分的第二个字段。鉴于这两个脚本都在 Python 中,将一个导入另一个然后直接传递字典不是更容易/更好吗?
标签: python