Circular import problem
the.mindstorm.mailinglist at gmail.com
Sun Jul 15 23:49:35 CEST 2007
On Jul 15, 10:08 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> En Sun, 15 Jul 2007 08:49:54 -0300, Alex Popescu
> <the.mindstorm.mailingl... at gmail.com> 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.
> >> That depends a bit on what is "MMA" and what is "grooves".
> >> MMA.grooves means "look for an attribute named grooves inside MMA". If
> >> MMA
> >> is a module, and MMA.grooves is a class/function defined inside the
> >> module, you don't need to import it before using it.
> > I am a bit confused: I think the above should be:
> > if MMA.grooves in a class/function defined inside the module MMA, you
> > don't need to import the
> > class/function before using it, but only import the module MMA.
> > Am I wrong?
> You are right, but we were talking about a slightly different scenario. To
> make things clear:
> import MMA
> import MMA.grooves
> If MMA is a module, containing a class named gooves, those two ways are
> If MMA is a package, and grooves is a module contained in the package,
> only the second one is valid (assuming the package has an empty
> __init__.py, or does not import grooves itself)
> The OP was asking why the second form worked fine for him for a while, but
> stopped working after reordering some imports. And the answer (according
> to "Greg") is: some other module imported MMA.grooves, and that put
> grooves into MMA namespace, available for everyone else.
> Gabriel Genellina
Now, everything is 100% clear.
.w( the_mindstorm )p.
More information about the Python-list