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 137 views
1 answer 164 views
1 answer 264 views
2 answers 241 views
1 answer 162 views
...