On 6 March 2014 11:34, William ML Leslie <[email protected]>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 <[email protected]>
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to