0

In ANSI C language I can take input until the EOF in the following way,

    while( scanf("%d",&number)!=EOF ) { //do something } 

I have searched for the way to perform it in python. All I got was this.

    while True:
        try:
        s=input()
        print("Do something")
    except EOFERROR:
    break

When I execute in python I get to put an input and it prints "Do something". But I don't know the way to stop the input taking as it does in C when I press Ctrl+Z. Here It doesn't work, it keeps taking inputs. If there is a way to do it in python pressing Ctrl+Z or there is some other method to put an end, please let me know.

Rajat Raja
  • 13
  • 1
  • 5

1 Answers1

1

you just have some simple syntactic/spelling issues:

while True:
        try:
            s=input()
            print("Do something")
        except EOFError:
            break

On Unix systems usually Ctrl+D is how you simulate an EOF from terminal

Easton Bornemeier
  • 1,918
  • 8
  • 22