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

Jim Fulton jim at zope.com
Tue Nov 22 09:47:41 EST 2005


Tres Seaver wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Jean-Marc Orliaguet wrote:
> 
>>There is another place where there seems to be two different patterns too:
>>
>>sometimes we have:
>>
>>  import zope.schema
>>  name = zope.schema.TextLine(...)
>>
>>and sometimes:
>>
>>  from zope.schema import TextLine
>>  name = TextLine(...)
>>
>>any reason to use one or the other (speed, verbosity, avoiding circular
>>imports, ...) ?
> 
> 
> I vastly prefer the second:  it keeps the use points clearer,

I don't know what you mean.  Perhaps you are refering to extra
clutter at point of use.  I'm sympathetic to this, especially
if something is used a lot.

I generally find the point of use clearer with the full dotted name, or,
for populat modules, like zope.component, zope.schema, etc:

   from zope import schema
   ...
   name = schema.TextLine(...)

I think this is largely a matter of taste.

...

> It is also ever-so-slightly faster, as it avoids a name lookup at
> point-of-use.  That optimization is the source of only downside of the
> practice:  it makes monkey-patching harder, because the original binding
> gets copied.

I generally only worry about the speed when something is going to be
called a lot, as in a tight loop or in a very popular function.  In cases
like those, I do prefer to import the name locally.

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