I am wondering how to run an indefinite while loop and to break it if the user (or a scripts outputting to the stdin of the present script) sends an EOF.
There are loads of specific post on SO but in all the ones I have seen, the user is asked at every iteration, for example
while True:
inp = input()
if inp != "":
print(2)
else:
print("I am out of here")
break
This is different from what I am looking for. My desired behaviour is that the user does not get asked, and only if they send EOF the loop breaks.
Something like
while True:
print(2)
# if EOF is received, break, if nothing is typed carry on looping
break