简体   繁体   中英

How to get User Input in Python 3 when input() returns errors

  • In python 3 I am getting errors when I use input() and I want to take user input and do something with it.
  • I am executing the python script in BBEdit, Sublime or IDLE.
  • Code results in errors unless I remove the Input() Syntax:

input("Hi I'm new to python")

userInput = input("Enter a string")
print(f"You entered {userInput}")

In the console it displays the string from input("String") but any user keystrokes are instead typed in the code editor, not interactively.

I read that Python could not be interactive via those apps but I don't understand how to execute a syntactically correct "input("enter your favorite sushi roll") and interact with it (on pc and Mac)

From Console:

Enter a string
Traceback (most recent call last):
File "/Users/michaelking/Desktop/BBEditRunTemp-hellowWorld.py", line 1, in userInput = input("Enter a string")
EOFError: EOF when reading a line
================================================================================ Nov 2, 2020 at 9:53:07 PM ~/Desktop/hellowWorld.py Traceback (most recent call last): File "/Users/michaelking/Desktop/BBEditRunTemp-hellowWorld.py", line 1, in userInput = input() EOFError: EOF when reading a line

userInput = input("Enter a string")
print("You entered {}".format(userInput))

When you're running a script that requires interactive input, you'll have to run it in Terminal (or an equivalent such as iTerm).

I can't speak to other products :-) but when using BBEdit, the "Run in Terminal" command on the #! menu will do this for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM