[issue4457] __import__ documentation obsolete
Mart Sõmermaa
report at bugs.python.org
Sun Nov 30 13:38:22 CET 2008
Mart Sõmermaa <mrts at mrts.pri.ee> added the comment:
Also, the examples that clarify __import__ behaviour by Nick Coghlan
should be added:
http://mail.python.org/pipermail/python-dev/2008-November/083735.html
---
"from foo.bar import baz" ---->
<stack top> = __import__('foo.bar', globals(), locals(), ['baz'], -1)
baz = <stack top>.baz
When there are multiple names being imported or an 'as' clause is
involved, I hope the reasons for doing it this way become more obvious:
"from foo.bar import baz, bob" ---->
<stack top> = __import__('foo.bar', globals(), locals(), ['baz', 'bob'], -1)
baz = <stack top>.baz
bob = <stack top>.bob
"from foo.bar import baz as bob" ---->
<stack top> = __import__('foo.bar', globals(), locals(), ['baz', 'bob'], -1)
bob = <stack top>.baz
---
And the "winning idiom" by Hrvoje Niksic for accessing module 'z', given
name hierarchy 'x.y.z' should be documented as well:
>>> import sys
>>> __import__('x.y.z')
>>> mod = sys.modules['x.y.z']
----------
nosy: +mrts
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4457>
_______________________________________
More information about the Python-bugs-list
mailing list