[melbourne-pug] Import questions

Brian May brian at microcomaustralia.com.au
Thu Mar 6 01:50:28 CET 2014


On 6 March 2014 11:34, William ML Leslie <william.leslie.ttg at gmail.com>wrote:

> specifically, 'import module' loads and initialises the module if needed,
> and then binds the name 'module' to the module.
>
> 'import package.module' loads and initialises package, and then module, if
> needed.  then, it binds the name 'package' to the top-level package.
>
> 'from module import name' loads and initialises the module if needed, and
> then binds the name 'name' to the value of 'module.name'.
>
> So the names within the current module are different for the two examples
> you give - the first binds '__version__' also, and the second binds
> 'module' also.
>

Seems to be that there is more to it then that.

For example. if in module/__init__.py I have:

   import module.something

I get an circular import loop. The import "module.something" seems to imply
an import of "module".

However, if instead, I do:

   from module.something import somethingelse

Then the circular import loop disappears.

I have read that there are certain other cases where 'import package.name'
will generate an error, but 'from package import name' won't.

Or am I totally confused?
-- 
Brian May <brian at microcomaustralia.com.au>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20140306/22087cdc/attachment-0001.html>


More information about the melbourne-pug mailing list