Article 5GZJP Python can't read script from stdin when input() appears in the script.

Python can't read script from stdin when input() appears in the script.

by
mimorek
from LinuxQuestions.org on (#5GZJP)
Hello,

When I let python run a short script from stdin it works, but not when the input() function appears in the script.
What is behind the EOFError and is there a way to make this work?

Thanks.

This fails:
Code:$ python3 <<HERE
> x = input()
> x = int(x)
> print(x**3)
> HERE
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError: EOF when reading a line
This works:
Code:$ python3 <<HERE
> x = 3**3
> print(x)
> HERE
27latest?d=yIl2AUoC8zA latest?i=vSwd2TTz4vA:fWCJfwvC9_0:F7zBnMy latest?i=vSwd2TTz4vA:fWCJfwvC9_0:V_sGLiP latest?d=qj6IDK7rITs latest?i=vSwd2TTz4vA:fWCJfwvC9_0:gIN9vFwvSwd2TTz4vA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments