'str' object is not callable, but I'm not using "str" at all

Viewed 886

I'm using Google Colab for development. My script only has one line of code where I'm supposed to read input from the console:

question = input("Hello")

But it is throwing this error: 'str' object is not callable

I search for similar problems and all of them where related to code using "str" as a variable or function name so it needed to be renamed, but in my case it is literally one line of code and I'm not using "str" at all.

Here is a screenshot of Google Colab:

enter image description here

3 Answers

I tried this in a brand new notebook and it worked. In your notebook it appears that input is not the built-in function to read user input but is actually a string of some sort.

To debug this further, try changing the code to just say input. Then it will print what the input identifier is bound to. You ought to see something like <bound method Kernel.raw_input of <google.colab._kernel.Kernel object at 0x7f9fb5f40210>>...

screenshot of new notebook

...but I suspect you'll see something else.

somewhere above you have

input = something_that_is_a_string

and that is shadowing the builtin input

dont name your variables input

You have a string variable named input previously in your code. Or perhaps you previously had such a variable and deleted the code, but the variable is still in the namespace. Just restart your Google Colab environment from the top menu: Runtime --> Restart Runtime. That will clear out all variables from memory and let you start over.

Related