Circular import problem
gagsl-py2 at yahoo.com.ar
Sun Jul 15 06:00:04 CEST 2007
En Sat, 14 Jul 2007 14:44:05 -0300, bvdp <bob at mellowood.ca> escribió:
>> > But, I still don't understand how python can access a function in a
>> > file I have NOT included. In this case, to get things to work, I DO
>> > NOT "import MMA.grooves" but later in the module I access a function
>> > with "xx=MMA.grooves.somefunc()" and it finds the function, and works
>> > just fine. It shouldn't work.
> I've just used an empty __init__.py file. I will have to read up a bit
> more on packages and see what advantage there is to import in that.
__init__.py is executed inside the package's namespace - whatever you
import/define there, is available later as packagename.zzz
> Which is considered good style? Loading at the top or loading when
I mean, importing at the top of the module is the recommended practice.
I try only to import locally: a) when it is slow and not always needed,
and b) when the imported module is unrelated to the main purpose (e.g.
import traceback inside some exception handlers).
More information about the Python-list