Commit c468abaf authored by Ezio Melotti's avatar Ezio Melotti

#18034: update FAQ to suggest importlib.import_module instead of __import__. ...

#18034: update FAQ to suggest importlib.import_module instead of __import__.  Patch by Wouter van Heyst.
parent ae410861
...@@ -1925,19 +1925,10 @@ These solutions are not mutually exclusive. ...@@ -1925,19 +1925,10 @@ These solutions are not mutually exclusive.
__import__('x.y.z') returns <module 'x'>; how do I get z? __import__('x.y.z') returns <module 'x'>; how do I get z?
--------------------------------------------------------- ---------------------------------------------------------
Try:: Consider using the convenience function :func:`~importlib.import_module` from
:mod:`importlib` instead::
__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`.
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? When I edit an imported module and reimport it, the changes don't show up. Why does this happen?
......
...@@ -545,6 +545,7 @@ Bernhard Herzog ...@@ -545,6 +545,7 @@ Bernhard Herzog
Magnus L. Hetland Magnus L. Hetland
Raymond Hettinger Raymond Hettinger
Kevan Heydon Kevan Heydon
Wouter van Heyst
Kelsey Hightower Kelsey Hightower
Jason Hildebrand Jason Hildebrand
Richie Hindle Richie Hindle
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment