Re: How to improve the usability of nested packages

Discussion in 'Python' started by Stefan H. Holek, Nov 2, 2012.

  1. Hi Michael,

    What we have learned from creating the Zope Toolkit (formerly Zope 3), is that __init__.py files in namespace packages should be empty, and imports should be absolute. [1]

    That said, there are ways to avoid import cycles. One is to very carefully craft your modules so they do not have to import from each other. Another is to not have imports at the module level, but move them into the functions where they are required. Third, large libraries like the Zope Toolkit usually have mechanisms to defer imports to some point after initial loading. You may want explore this direction as well. [2]

    (Not trying to plug the ZTK here, it just happens to be a large, namespace-using library I know.)

    Hope this helps,
    Stefan

    [1] http://docs.zope.org/zopetoolkit/
    [2] http://pypi.python.org/pypi/zope.deferredimport

    --
    Stefan H. Holek
    Stefan H. Holek, Nov 2, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul  Smith
    Replies:
    0
    Views:
    723
    Paul Smith
    Nov 18, 2003
  2. Esmail
    Replies:
    8
    Views:
    318
    Esmail
    Mar 21, 2009
  3. David Lyon
    Replies:
    19
    Views:
    561
    David Lyon
    Apr 24, 2009
  4. Michael Schwarz
    Replies:
    1
    Views:
    182
    Rouslan Korneychuk
    Nov 6, 2012
  5. Terry Reedy
    Replies:
    0
    Views:
    130
    Terry Reedy
    Nov 2, 2012
Loading...

Share This Page