Gary Poster wrote:
On Nov 21, 2005, at 12:29 PM, Jean-Marc Orliaguet wrote:
There is another place where there seems to be two different patterns
sometimes we have:
name = zope.schema.TextLine(...)
from zope.schema import TextLine
name = TextLine(...)
FWIW, a third is
from zope import schema
which I often do for zope.component, zope.interface, zope.event, and
I'm not weighing in on the style issues.
- For obscure things that are used only a few times in a module,
and especially for things that are used only during module import,
I prefer the first form. This makes the code easier to read because you
don't have to refer to the imports. It also tends to make the imports
shorter and easier to manage.
- For popular modules like component, interface, and schema, I strongly
prefer the thirs option because it keeps the imports simpler, and
falls between the two extremes.
A variation of the the third option that I also like for similar reasons
as above occurs when importing sibling modules within the same package.
For example, suppose we have modules foo and interfaces within mypackege.
In foo, if I wanted to get to interfaces, I would use:
from zope import interface
from mypackage import interfaces
This gives us the same effect as if we had done a relative import of
without breaking the no-relative-import rule.
- I prefer the second form for well-known objects that are
used a lot.
For cases that fall between these extremes, I tend to
prefer the first form.
I think this is a matter of taste and art. I'm not very keen
to legislate this. :)
Jim Fulton mailto:[EMAIL PROTECTED] Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
Zope3-dev mailing list