# second.py
from .first import get_numbers
# the method using the numbers (formerly getting them from stdin)
def process_numbers():
numbers = get_numbers()
# do something to process the numbers
如果您确实想按原样调用另一个脚本,可以这样做:
#second.py
from subprocess import Popen, PIPE
def process_numbers():
p = Popen(["first.py", "argument"], stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
# the out variable now contains the standard output of the first script
# do something to process the numbers
请考虑以下选项:
1)使用如下管道从shell运行两个脚本:
2)重新编写脚本,以便在第二个脚本中导入第一个脚本,例如:
第一个脚本:
^{pr2}$第二个脚本:
如果您确实想按原样调用另一个脚本,可以这样做:
如果你真的要这样做,你可以考虑一下:
对于list或dict,在准备要传递/接收的数据时,可以考虑使用
pickle
。在相关问题 更多 >
编程相关推荐