I am working on a script with user input in Py 3.6.
In the script, the user is asked to enter a text section - potentially containing new lines - into the shell. The entered text will then be saved to a Python variable for further processing.
Since the user input may contain newlines, I think I cannot use input()
but am using sys.stdin.read()
(as suggested here).
Problem
Reading in the input works fine, but to end the user input, the user has to hit Return and then use the key combination CTRL + d
(see here). (See Current Procedure below)
Question
- I would prefer that the user can just end their input to
sys.stdin.read
by hitting the Return key (cf Expected Procedure below)
EDIT: Any other simplification to the current process with CTRL + d
is appreciated as well.
Is this doable?
There are some hacks here but I thought maybe there is a better way
Current code
# display text on screen
print("Review this text\n" + text)
# user will copy and paste relevant items from text displayed into Terminal
user_input = sys.stdin.read()
print ("hit ctrl + d to continue")
# process `user_input`
Current procedure
With the current code reproduced below, the user has to
1) paste the text
2) hit RETURN
to end input
3) hit Ctrl+d
to move to next file
Expected procedure
I would like to reduce this to:
1) paste the text
2) hit RETURN
to end input and move to next file
Running Python 3.5.6 on MacOSX, using Terminal for text input. Any help is much appreciated!