Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am a novice to Python and following a tutorial. There is an example of list in the tutorial :

example = list('easyhoss')

Now, In tutorial, example= ['e','a',...,'s']. But in my case I am getting the following error:

>>> example = list('easyhoss') 

Traceback (most recent call last): 

 File "<stdin>", line 1, in <module> 

TypeError: 'list' object is not callable

Please tell me where I am wrong. 

1 Answer

0 votes
by (106k points)
edited by

It looks like you have shadowed the built-in name list which is pointing at a class by the same name where it is pointing at its instance. Here is an example:-

>>> example = list('easyhoss') 

>>> list = list('abc') 

>>> example = list('easyhoss') 

Traceback (most recent call last): 

 File "<string>", line 1, in <module> 

TypeError: 'list' object is not callable

There can be two main reasons the error you are getting:-

  • Namespaces:- The first reason is Python supports nested namespaces. Any module you create gets its own "global" namespace. In fact, it's just a local namespace with respect to that particular module.

  • Scoping. The second reason is when you reference a name, the Python runtime looks it up in the local namespace (with respect to the reference) and, if such name does not exist, it repeats the attempt in a higher-level namespace. This process continues until there are no higher namespaces left. In that case, you get a NameError

So whenever you start an interactive Python session you should create a temporary module.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
+1 vote
1 answer
0 votes
0 answers
asked Jun 24, 2021 in Python by priyanka (120 points)
0 votes
1 answer
asked Sep 26, 2019 in Python by Sammy (47.6k points)

Browse Categories

...