Problem with python 3.2 and circular imports

Frank Millman frank at chagford.com
Sun Mar 6 02:56:34 EST 2011


"Rafael Durán Castañeda" <rafadurancastaneda at gmail.com> wrote...

> Thank you for your answer Frank, I think I've found the problem. I was
> calling modules from inside subpackages, and I need to use them from
> outside, so I have package in PYTHONPATH. is that correct? But now I have
> another question: Can I execute an script inside subpackage1 importig
> modules from subpackage2?

Hi Rafael

I am no expert, so I cannot answer you directly.

In my case, my program started as a single module.

As it grew, I started to split some parts off and store them in separate 
modules in the same directory. I placed 'import' statements in the main 
module, and it worked.

Then I found the need for some modules to refer to objects in other modules, 
so I needed 'import' statements within the modules. I found myself hitting 
problems with circular imports from time to time, but with some help from 
this group and re-reading the docs I got over this hurdle.

Only recently has my project got big enough to start thinking about 
packages. It adds complexity, but by reading the docs again, and thinking 
carefully about the structure, I have so far managed to handle the problems 
that occur.

I found the 'modules' chapter in the tutorial a good place to start. Once 
you have fully grasped the contents, PEP 328 is a good resource for 
understanding what has changed in python 3.x.

BTW, this group prefers 'bottom posting'. You will see that I have placed my 
response below yours. If you want to reply to this, please follow the same 
practice.

Hope this helps to get you started.

Frank





More information about the Python-list mailing list