I am new to Python programming language reading books and attending some online courses.
I am currently using the Visual Studio Code software.
During working on the “input” function, I typed “>>> name = input(‘ […]” (I ommitted the details) and I received the following message from the aforementioned software:
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘str’ object is not callable
However, I typed the same command using the simple code editor that accompanies the python software, and I did not receive any mistake-related message.
Could anybody explain what is happening?
Thank you in advance.
I ommitted the details
The details actually matter though…
We probably need to see your full code to be sure, but you shadowed the
input by creating a
variable named input.
You are getting an error because you have a string and tried to call it like a function.
That’s all there is to say, given you decided to share virtually no code.
The full command is:
name = input(‘What is your name?\n’)
(it is from a book)
When I type this command to the simple code editor it is ok.
The error message appears only with the Visual Studio Code.
Then go through the code and look for the word “input”?
There propably is a line like
input = "some text" → Python will then just override the keyword with the string. That’s what Jeremy meant with “shadowed”, somewhere in the code, this is happening.
As I am not super educated on the Python interpreter, I cannot say if the shadowing has to happen in a prior line or could be anywhere in the file or even imported modules…
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.