Namespace confusion

Oleg Broytmann phd at phd.pp.ru
Fri Sep 14 14:23:17 CEST 2001


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

On Fri, Sep 14, 2001 at 02:17:25PM +0200, Luna Tic wrote:
> 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.

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list