]> granicus.if.org Git - python/commitdiff
Closes #9254: backport __import__ docstring/doc mentions of importlib.
authorR David Murray <rdmurray@bitdance.com>
Wed, 18 Jul 2012 23:44:08 +0000 (19:44 -0400)
committerR David Murray <rdmurray@bitdance.com>
Wed, 18 Jul 2012 23:44:08 +0000 (19:44 -0400)
Patch by Éric Araujo.

Doc/library/functions.rst
Python/bltinmodule.c

index a324e51317a2d307bf8f0b691f2e564a3dbbed04..dc8ee9a454dc57e1669fa65832d2407fc540edfc 100644 (file)
@@ -1558,7 +1558,7 @@ available.  They are listed here in alphabetical order.
    .. note::
 
       This is an advanced function that is not needed in everyday Python
-      programming.
+      programming, unlike :func:`importlib.import_module`.
 
    This function is invoked by the :keyword:`import` statement.  It can be
    replaced (by importing the :mod:`__builtin__` module and assigning to
@@ -1609,15 +1609,8 @@ available.  They are listed here in alphabetical order.
    names.
 
    If you simply want to import a module (potentially within a package) by name,
-   you can call :func:`__import__` and then look it up in :data:`sys.modules`::
-
-      >>> import sys
-      >>> name = 'foo.bar.baz'
-      >>> __import__(name)
-      <module 'foo' from ...>
-      >>> baz = sys.modules[name]
-      >>> baz
-      <module 'foo.bar.baz' from ...>
+   use :func:`importlib.import_module`.
+
 
    .. versionchanged:: 2.5
       The level parameter was added.
index 373f8706245c8133b64752089a07936a02ee026d..3def0800aaabb5b4ead4de480bb3ecd3c9f0d458 100644 (file)
@@ -53,8 +53,12 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR(import_doc,
 "__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module\n\
 \n\
-Import a module.  The globals are only used to determine the context;\n\
-they are not modified.  The locals are currently unused.  The fromlist\n\
+Import a module. Because this function is meant for use by the Python\n\
+interpreter and not for general use it is better to use\n\
+importlib.import_module() to programmatically import a module.\n\
+\n\
+The globals argument is only used to determine the context;\n\
+they are not modified.  The locals argument is unused.  The fromlist\n\
 should be a list of names to emulate ``from name import ...'', or an\n\
 empty list to emulate ``import name''.\n\
 When importing a module from a package, note that __import__('A.B', ...)\n\