(original) (raw)
changeset: 71602:7bfc0a45542c branch: 3.2 parent: 71600:f02a8f906342 user: Éric Araujo merwok@netwok.org date: Fri Jul 29 17:50:58 2011 +0200 files: Doc/library/functions.rst description: Let the doc of __import__ link to importlib (#9254). importlib.import_module eschews a number of issues that __import__ has. Reviewed by Brett Cannon. (The docstring of __import__ was already updated in 3d490c3a019e, for #7397.) diff -r f02a8f906342 -r 7bfc0a45542c Doc/library/functions.rst --- a/Doc/library/functions.rst Fri Jul 29 17:03:55 2011 +0200 +++ b/Doc/library/functions.rst Fri Jul 29 17:50:58 2011 +0200 @@ -1387,7 +1387,7 @@ .. 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:`builtins` module and assigning to @@ -1437,15 +1437,8 @@ 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`:: + use :func:`importlib.import_module`. - >>> import sys - >>> name = 'foo.bar.baz' - >>> __import__(name) - - >>> baz = sys.modules[name] - >>> baz - .. rubric:: Footnotes/merwok@netwok.org