Python sys.stdin.read(1) in a while(True) loop consistently executes 1 time getting input and multiple times not getting input

前端 未结 2 1266
长发绾君心
长发绾君心 2021-01-27 00:01

I\'m running python 2.7 on 64-bit Windows 7.

Here is the code i\'m executing:

import sys
while True:
    print \'please enter a character:\'
    c = sys.         


        
2条回答
  •  既然无缘
    2021-01-27 00:36

    Problem is probably due to flushing of stdin since the \n lingers on.

    as an alternative, use raw_input

    while True:
        c = raw_input('please enter a character: ')
        print 'you entered', c
    

    For the flushing part, see this

提交回复
热议问题