Can someone explain this behavior to me?

ma mabdelkader at gmail.com
Thu Feb 26 17:25:38 EST 2009


I'm pretty sure that Foo is getting replaced once you import Foo, why not
pass the Foo() object to bar's go? I'm sure there are other ways, but yes,
circular imports are indeed evil.


On Thu, Feb 26, 2009 at 5:13 PM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Thu, Feb 26, 2009 at 1:48 PM, Jesse Aldridge <JesseAldridge at gmail.com>
> wrote:
> > I have one module called foo.py
> > ---------------------
> > class Foo:
> >    foo = None
> >
> > def get_foo():
> >    return Foo.foo
> >
> > if __name__ == "__main__":
> >    import bar
> >    Foo.foo = "foo"
> >    bar.go()
> > ---------------------
> > And another one called bar.py
> > ---------------------
> > import foo
> >
> > def go():
> >    assert foo.get_foo() == "foo"
> > ----------------------
> > When I run foo.py, the assertion in bar.py fails.  Why?
>
> Not sure, but circular imports are *evil* anyway, so I'd suggest you
> just rewrite the code to avoid doing any circular imports in the first
> place.
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...
> http://rebertia.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090226/fc697782/attachment-0001.html>


More information about the Python-list mailing list