How to read characters with a while loop from standard input (keyboard) until user press Enter in Python

1 Answer

0 votes
import sys

text = ""
while 1:
    ch = sys.stdin.read(1)
    text = text + ch
    if ch == '\n':
        break

print("User Input: %s" % text)


'''
run:

python programming is fun
User Input: python programming is fun

'''

 



answered Dec 12, 2017 by avibootz

Related questions

1 answer 134 views
1 answer 160 views
1 answer 255 views
2 answers 230 views
1 answer 156 views
...