Probably an easy question, but I am basically trying to replicate the behavior (very sparsely and simplistically) of the cat
command but in python. I want the user to be able to enter all the text they wish, then when they enter an EOF (by pressing ctrl+d
or cmd+d
) the program should print out everything they enter.
import sys
for line in sys.stdin:
print line
If I enter the input lines and follow the last line with a return character, and then press cmd+d
:
never gonna give you up
never gonna let you down
never gonna run around
and desert you
then the output is
never gonna give you up
never gonna let you down
never gonna run around
and desert you
However, if I press cmd+d
while I am still on the last line "and desert you
" then the output is:
never gonna give you up
never gonna let you down
never gonna run around
How can I modify the program such that if the user presses the EOF on the last line, then it should still be included as part of the output?