[Python-checkins] cpython (3.4): #18034: update FAQ to suggest importlib.import_module instead of __import__.

ezio.melotti python-checkins at python.org
Mon Aug 4 18:36:06 CEST 2014


http://hg.python.org/cpython/rev/815f1a69283e
changeset:   91996:815f1a69283e
branch:      3.4
parent:      91994:9bca86812857
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Mon Aug 04 19:34:29 2014 +0300
summary:
  #18034: update FAQ to suggest importlib.import_module instead of __import__.  Patch by Wouter van Heyst.

files:
  Doc/faq/programming.rst |  15 +++------------
  Misc/ACKS               |   1 +
  2 files changed, 4 insertions(+), 12 deletions(-)


diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1786,19 +1786,10 @@
 __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?
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -549,6 +549,7 @@
 Magnus L. Hetland
 Raymond Hettinger
 Kevan Heydon
+Wouter van Heyst
 Kelsey Hightower
 Jason Hildebrand
 Richie Hindle

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list