r/programminghelp • • Feb 28 '20

Python Help finding Python documentation on sys.stdin.read() or another multiline user input method

So te thing is, I want to get a multiline input from the user. After some searching i found the suggestion of using sys.stdin.read() . Which is supposed to be able to do this with the ending character being Ctrl + D. But when I try it it wont end the input. So I need help with finding the doc on the matter. And/or another solution.

4 Upvotes

1 comment sorted by

View all comments

1

u/07734willy Feb 29 '20

You could try using a SIGINT / ctrl-C to raise a KeyboardInterrupt exception, catch that, and proceed.

import sys

try:
    text = sys.stdin.read()
except KeyboardInterrupt:
    # do something with `text`

Otherwise, you could try using non-blocking input, and then break when you receive a specific character or character + modifier.