diff options
author | Thomas Wouters <thomas@python.org> | 2000-08-19 20:55:02 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2000-08-19 20:55:02 (GMT) |
commit | 8bad61288186aab93b8aaf6b229c07211e1c77d7 (patch) | |
tree | 2c03c8261f7a1b91c433f20245638154b0629879 /Doc/ref | |
parent | 15446d344d2bda98bf8fd7d0244081a9d4bb7c8f (diff) | |
download | cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.zip cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.tar.gz cpython-8bad61288186aab93b8aaf6b229c07211e1c77d7.tar.bz2 |
Disallow "import mod.submod as m", because the result is ambiguous. Does it
load mod.submod as m, or mod as m ? Both can be achieved differently, and
unambiguously. Also attempt to document this restriction (editor
appreciated!)
Note that this is an artificial check during compile, because incorporating
this in the grammar is hard, and then adjusting the compiler to do the right
thing with the right nodes is harder.
Diffstat (limited to 'Doc/ref')
-rw-r--r-- | Doc/ref/ref6.tex | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Doc/ref/ref6.tex b/Doc/ref/ref6.tex index 008cf1c..3f21479 100644 --- a/Doc/ref/ref6.tex +++ b/Doc/ref/ref6.tex @@ -498,7 +498,12 @@ begin. The first form of \keyword{import} statement binds the module name in the local namespace to the module object, and then goes on to import the next identifier, if any. If the module name is followed by \keyword{as}, -the name following \keyword{as} is used as the local name for the module. +the name following \keyword{as} is used as the local name for the module. To +avoid confusion, you cannot import sub-modules 'as' a different +local name. So 'import module as m' is legal, but 'import module.submod as +s' is not. The latter should be written as 'from module import submod as s', +see below. + The \keyword{from} form does not bind the module name: it goes through the list of identifiers, looks each one of them up in the module found in step (1), and binds the name in the local namespace to the object thus found. |