Namespace confusion

Luna Tic lunatic at beyond.net
Fri Sep 14 14:17:25 CEST 2001


Hi all,

consider a file (foo) containing the following statements:

import bar
class foo:
        def __init__(self):
                self.attr = bar.bacon()
                self.list = []

i = foo()


Now consider another file (bar), containing the class definition (bacon) 
that is imported into the file above. This class definition wants to access 
the file above and do something like 'i.list.append(1)'.

If I try something like this:

import foo
class bacon:
        def __init__(self):
                foo.i.list.append(1)


I get an error message certainly because of the interdependence of those 
two modules, am I right?

How then can I resolve this issue? Note that I'd like to keep those two 
files separated.

Thanks for your answers!

LunaTic




More information about the Python-list mailing list