Problem with python 3.2 and circular imports

Ben Finney ben+python at benfinney.id.au
Sun Feb 27 07:44:46 EST 2011


"Frank Millman" <frank at chagford.com> writes:

> Assume the following structure -
>
> main.py
> /pkg
>    __init__.py
>    mod1.py
>    mod2.py
>
> main.py
>    from pkg import mod1
>
> mod1.py
>    import mod2
>
> mod2.py
>  import mod1

What are you expecting the result to be?

If it's about sharing objects between the modules, why not break the
circular dependency: factor out the common code to a module that both
the others import?

> Any comments or suggestions will be appreciated.

Special cases aren't special enough to break the rules. If you think you
have a practical reason to do so, it would be best to make it explicit
when asking for help about this.

-- 
 \           “The long-term solution to mountains of waste is not more |
  `\      landfill sites but fewer shopping centres.” —Clive Hamilton, |
_o__)                                                _Affluenza_, 2005 |
Ben Finney



More information about the Python-list mailing list