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

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


http://hg.python.org/cpython/rev/46c7a724b487
changeset:   91998:46c7a724b487
branch:      2.7
parent:      91978:50722d2f08c7
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 |  17 ++++-------------
  Misc/ACKS               |   1 +
  2 files changed, 5 insertions(+), 13 deletions(-)


diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1925,19 +1925,10 @@
 __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?
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -545,6 +545,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