[melbourne-pug] Import questions

William ML Leslie william.leslie.ttg at gmail.com
Thu Mar 6 01:34:27 CET 2014


On 6 March 2014 11:16, Brian May <brian at microcomaustralia.com.au> wrote:
>
>
> [2] Also, on a separate thread, can somebody point me to a document that
> describes the difference between the two forms of import in as described in
> [1]? It seems that they are different.
>

The best place to find answers for all language questions is the langref.

http://docs.python.org/3/reference/simple_stmts.html#the-import-statement

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.

-- 
William Leslie

Notice:
Likely much of this email is, by the nature of copyright, covered under
copyright law.  You absolutely may reproduce any part of it in accordance
with the copyright law of the nation you are reading this in.  Any attempt
to deny you those rights would be illegal without prior contractual
agreement.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20140306/1d88a325/attachment.html>


More information about the melbourne-pug mailing list