[melbourne-pug] Import questions

Ben Finney ben+python at benfinney.id.au
Thu Mar 6 02:09:16 CET 2014


Brian May <brian at microcomaustralia.com.au> writes:

> For example. if in module/__init__.py I have:
>
>    import module.something
>
> I get an circular import loop.

Don't do that, then. Within the package ‘__init__’ module, don't refer
to the package.

Instead, use a relative import::

    from . import foo

or::

    from .foo import bar

See <URL:http://docs.python.org/3.0/tutorial/modules.html#intra-package-references>.

-- 
 \         “If nature has made any one thing less susceptible than all |
  `\    others of exclusive property, it is the action of the thinking |
_o__)                          power called an idea” —Thomas Jefferson |
Ben Finney



More information about the melbourne-pug mailing list