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