Can someone explain this behavior to me?

Chris Rebert clp2 at rebertia.com
Thu Feb 26 17:13:29 EST 2009


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



More information about the Python-list mailing list