This might be a silly question, but as I can't find an answer, I have to ask it.
In interactive python I want to process a message which i get with:
>>> message = sys.stdin.readlines()
Everything works fine, but... how to stop it from getting an input and make it save into message variable? Stopping with ctrl+c stops whole process so there is no input to be saved anywhere. I guess there's an easy answer I just can't find...
stdin. readline() Stdin stands for standard input which is a stream from which the program reads its input data. This method is slightly different from the input() method as it also reads the escape character entered by the user.
stdin. readline() is the fastest one when reading strings and input() when reading integers.
For unix based system :
Hello, you can tape : Ctrld
Ctrld closes the standard input (stdin) by sending EOF.
Example :
>>> import sys >>> message = sys.stdin.readlines() Hello World My Name Is James Bond # <ctrl-d> EOF sent >>> print message ['Hello\n', 'World\n', 'My\n', 'Name\n', 'Is\n', 'James\n', 'Bond\n']
For Windows :
To send EOF on Windows, you can replace Ctrld by Ctrlz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With