How to quit from input() function after call codecs.getreader for stdin?

时间:2015-10-30 23:02:28

标签: python windows utf-8 console

I try to read from windows console utf-8 letters.

I have the code follows:

import codecs
sys.stdin = codecs.getreader('utf-8')(sys.stdin)

if __name__ == '__main__':    
    print 'query=',
    query = sys.stdin.readline()
    print query 

But there is a strange thing:

After pressing the enter button the execution of the stdin.readline() or raw_input() or input() functions will not stop.

What do I do wrong? Or how to send eof() to stop input from console in this case?

1 个答案:

答案 0 :(得分:1)

On my Mac, hitting ^D (Ctrl-D) twice does the trick. Not sure if this will work across systems, but give it a shot.