【发布时间】:2014-11-22 17:28:14
【问题描述】:
我在 Windows 7 上使用 Python 2.7.6 和 IDLE。
我有 2 个 Python 脚本:
脚本.py:
import subprocess, os, sys
print("hello 1")
mypath = os.path.abspath(__file__)
mydir = os.path.dirname(mypath)
start = os.path.join(mydir, "script2.py")
subprocess.call([sys.executable, start, "param"])
print("bye 1")
以及被前一个脚本调用的 script2.py:
import sys
print "hello 2"
print (sys.argv[1])
print "bye 2"
如果我使用 cmd.exe shell 运行 script.py,我会得到预期的结果:
C:\tests>python ./script.py
hello 1
hello 2
param
bye 2
bye 1
但如果我使用 IDLE 编辑器打开 script.py 并使用 F5 运行它,我会得到以下结果:
>>> ================================ RESTART ================================
>>>
hello 1
bye 1
>>>
为什么子脚本没有写入 IDLE Python shell?
【问题讨论】:
标签: python shell windows-7 python-idle