for line in sys.stdin: do_whatever()# End of stream!do_whatever_else()
It's that simple.
Use try/except. Input
When EOF is read, EOFError is raised.
while True: try: s=input("> ") except EOFError: print("EOF") break