0

python -i <script.py>理论上意味着运行script.py并进入交互模式,但是:

shell$ python -i print_content.py < file.txt
hello world

>>>
shell$

脚本运行成功,后面跟着打印,表示脚本执行后进入>>>了 Python shell 。

我知道我可以通过从脚本中打开文件来绕过这个问题——我更想知道问题的原因。

注意: print_content.py 的内容看起来很无辜:

import sys
for i in sys.stdin:
    print i

注意:我使用的是 Python 2.7.3

4

0 回答 0