[Zope-dev] Coding style clarifications

Jim Fulton jim at zope.com
Fri Feb 20 10:31:14 EST 2009


On Feb 20, 2009, at 10:15 AM, Martijn Faassen wrote:

> Jim Fulton wrote:
>
>> BTW, I strongly discourage from imports. (I didn't always have this
>> opinion, but have seen the error of my ways. Thanks to Fred Drake for
>> nudging me in this direction.) IMO, this is wildly more important  
>> than
>> any of the issues raised in this thread.
>
> I like from imports as they allow me to provide a public API in the
> __init__.py of a package (instead of scattering it all over the  
> place in
> sub-modules of the package nobody should need to know about). Absolute
> imports tend to break this ability in subtle ways.
>
> I suspect there are two possibilities:
>
> * no API defined in __init__.py and absolute imports
>
> * API defined in __init__.py and dotted.package.name.references  
> don't work.

In what way don't they work?

I don't see how this has anything to do with from imports.  Putting an  
API in the package __init__ just makes object paths shorter.  I don't  
see how the location of an API has much bearing on whether to use from  
imports or not.

> This looks like a religious debate though.


Maybe. The most important reason for a style guide is to make code  
more readable.  In my experience, from imports make code significantly  
harder to read, so this is fairly important to me.

Jim

--
Jim Fulton
Zope Corporation




More information about the Zope-Dev mailing list