1

当我在 python 模块(Python 3.3)中运行它时,我有一些运行得很好的代码。但是,当我将它设为可执行文件并尝试在我的 Mac 终端中运行它时,什么也没有打印出来。

代码的开头:

#!/usr/bin/python

import sys

marker = 1
prevchar = 'z'
prevstring = ""
#print("At place 1")

for line in sys.stdin:
    #print("At place 2")
    sys.stdout.write("% ")
    for c in line:
        #print("Starting loop")

在终端中,当我取消“print(“At place 1”)”的注释时,它会打印出来。但是,对于“print("At place 2")" 则不起作用。怎么了?

编辑:我只需将数据输入终端即可将数据输入标准输入。不过,也许阅读文件会更好?

4

1 回答 1

1

你怎么跑?你需要在你的情况下管道一些东西。

cat test | python sys_test_module.py
 At place 1
 At place 2
 At place 2

您可能会发现这很有帮助http://en.wikibooks.org/wiki/Python_Programming/Input_and_output

于 2013-10-15T01:35:44.833 回答