简体   繁体   English

Python无法在Mac终端中打印

[英]Python not printing in Mac terminal

I have some code that runs perfectly fine when I run it in the python module (Python 3.3). 当我在python模块(Python 3.3)中运行某些代码时,它们运行得非常好。 However, when I make it an executable and try to run it in my Mac terminal nothing prints out. 但是,当我将其设为可执行文件并尝试在Mac终端中运行该文件时,不会打印任何内容。

The beginning of the code: 代码的开头:

#!/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")

In the terminal, when I take the comment sign off of "print("At place 1")", it prints. 在终端中,当我取下“ print(“ At place 1”)“的注释符号时,将进行打印。 However, the same does not work for "print("At place 2")". 但是,“ print(“ At place 2”)“则不起作用。 What's wrong? 怎么了?

EDIT: I am putting data into stdin by just typing it into terminal. 编辑:我只是通过将数据输入到终端将数据放入标准输入。 Maybe reading through a file would be better, though? 不过,也许通读文件会更好?

How do you run? 你怎么跑? You need to pipe something in you case. 在这种情况下,您需要传递一些内容。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM