class instance scope

Ritesh Raj Sarraf riteshsarraf at gmail.com
Mon Jul 24 07:09:01 EDT 2006


Hi,

I have a class defined in a file called foo.py

In bar.py I've imported foo.py
In bar.py's main function, I instantiate the class as follows:

log = foo.log(x, y, z)

Now in main I'm able to use log.view(), log.error() et cetera.

But when I call the same method from some functions which are in
bar.py, it fails giving me the following error:

NameError: global name 'log' is not defined

1) I tried lookng into the docs but couldn't find anything on instance
scope.
2) How is such situation tackled ? Will I have to instantiate in every
function ?

Ritesh




More information about the Python-list mailing list