[Tutor] TypeError: 'str' object is not callable

Erik Price erikprice at mac.com
Sun Sep 7 11:52:35 EDT 2003


On Sunday, September 7, 2003, at 02:44  AM, Tony Cappellini wrote:

> This error message is displayed when either of the calls to exit() are 
> executed- but I don't understand why.
>
> Exiting
> Traceback (most recent call last):
>   File "walk.py", line 19, in ?
>   File "E:\apps\Python\lib\ntpath.py", line 324, in walk
>     walk(name, func, arg)
>   File "E:\apps\Python\lib\ntpath.py", line 318, in walk
>     func(arg, top, names)
>   File "walk.py", line 15, in printdirname
> TypeError: 'str' object is not callable
>
>
> Would someone please explain which str object is being called ?

The str object being called is a string named 'exit' in the built-in 
attributes (see the __builtins__ module for a list of these, or just 
type "dir(__builtins__)" at the prompt).  It exists so that if someone 
types "exit" from the prompt, there is a convenient and unmagical way 
to give the user the message that the proper way to exit the prompt is 
with EOF, not "exit" (because "exit" could be bound to some other 
object).

I think what you mean to do in your code is call the os.exit function, 
as opposed to the string named "exit" in the built-ins.


Erik




More information about the Tutor mailing list