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

Lee Harr missive at hotmail.com
Sun Sep 7 14:12:04 EDT 2003


>   File "walk.py", line 15, in printdirname
>TypeError: 'str' object is not callable
>
>
>import os
>import time
>
>def    printdirname(junk, dirpath, namelist):
>
>        try:
>            for name in namelist:
>                if( os.path.isdir(name) ):
>                         print "%s" % name
>
>        except KeyboardInterrupt:
>            print "\nExiting"
>            exit(0)
>
>if __name__ == '__main__':
>    try:
>        os.path.walk(r"e:\src\python", printdirname, "*.*")
>    except KeyboardInterrupt:
>        print"\nExiting from Exception during call to os.path.walk()"
>        exit(0)
>


Hi;

Is this really all of the code?  :o)

I do not see exit bound anywhere, so I think the str is whatever
exit is bound to.

Usually, when I really _really_ want to get out of a program
right NOW, I do this:

import os
os._exit(0)

Maybe exit is being bound somewhere inside of os.path.walk
and some kind of namespace thing is letting it waft out in to
your handler....

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus




More information about the Tutor mailing list