mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
#18034: update FAQ to suggest importlib.import_module instead of __import__. Patch by Wouter van Heyst.
This commit is contained in:
parent
69fb6a41c5
commit
e4aad5ab32
2 changed files with 4 additions and 12 deletions
|
|
@ -1786,19 +1786,10 @@ These solutions are not mutually exclusive.
|
|||
__import__('x.y.z') returns <module 'x'>; how do I get z?
|
||||
---------------------------------------------------------
|
||||
|
||||
Try::
|
||||
|
||||
__import__('x.y.z').y.z
|
||||
|
||||
For more realistic situations, you may have to do something like ::
|
||||
|
||||
m = __import__(s)
|
||||
for i in s.split(".")[1:]:
|
||||
m = getattr(m, i)
|
||||
|
||||
See :mod:`importlib` for a convenience function called
|
||||
:func:`~importlib.import_module`.
|
||||
Consider using the convenience function :func:`~importlib.import_module` from
|
||||
:mod:`importlib` instead::
|
||||
|
||||
z = importlib.import_module('x.y.z')
|
||||
|
||||
|
||||
When I edit an imported module and reimport it, the changes don't show up. Why does this happen?
|
||||
|
|
|
|||
|
|
@ -549,6 +549,7 @@ Bernhard Herzog
|
|||
Magnus L. Hetland
|
||||
Raymond Hettinger
|
||||
Kevan Heydon
|
||||
Wouter van Heyst
|
||||
Kelsey Hightower
|
||||
Jason Hildebrand
|
||||
Richie Hindle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue