[Zope3-dev] __init__.py interfaces.py guidelines?

Jim Fulton jim at zope.com
Mon Nov 21 10:45:46 EST 2005


Jean-Marc Orliaguet wrote:
> Jim Fulton wrote:
> 
>>
>>>
>>> yes indeed, but no "cross" imports between packages that are siblings.
>>
>>
>>
>> Huh? Why? I'm not at all sure I know what you mean.
> 
> 
> 
> the question is what relation between the importer and the imported are 
> OK: if I add such imports in __init__.py, I should only import from 
> packages located in the same folder or in subfolders but not  from 
> sibling folders or from parent folders.

Ah. Right. Agreed.

> with a directory structure like:
> 
> root/
> 
> - packageA
>  |__ packageB
> 
> - packageC
> 
> in packageA.__init__.py it is OK  to add:
> 
>    from root.packageA.somefile import somemodule
> 
> to make it possible for external packages to import "somemodule" as:
> 
>    from root.packageA import somemodule
> 
> it is OK to write in packageA.__init__.py :
> 
>    from root.packageA.packageB.somefile import someothermodule
> 
> to import it as:
> 
>    from root.packageA import someothermodule
> 
> but it is not OK to put the same imports in packageC (a sibling), which 
> be some sort or cross import between packages that are not parent / 
> child to one another. This easily leads to circular imports.
> 
> so what I mean is : parents import from children to make it possible for 
> external packages to import directly from the parents.

Yup.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope3-dev mailing list