" python -i print_content.py< file.txt的"退出交互模式

时间:2017-05-06 22:06:00

标签: python bash command-line python-interactive

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

0 个答案:

没有答案