Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
59488d23
Commit
59488d23
authored
Jul 18, 2012
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #9254: backport __import__ docstring/doc mentions of importlib.
Patch by Éric Araujo.
parent
0e3755e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
12 deletions
+9
-12
Doc/library/functions.rst
Doc/library/functions.rst
+3
-10
Python/bltinmodule.c
Python/bltinmodule.c
+6
-2
No files found.
Doc/library/functions.rst
View file @
59488d23
...
@@ -1558,7 +1558,7 @@ available. They are listed here in alphabetical order.
...
@@ -1558,7 +1558,7 @@ available. They are listed here in alphabetical order.
.. note::
.. note::
This is an advanced function that is not needed in everyday Python
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
This function is invoked by the :keyword:`import` statement. It can be
replaced (by importing the :mod:`__builtin__` module and assigning to
replaced (by importing the :mod:`__builtin__` module and assigning to
...
@@ -1609,15 +1609,8 @@ available. They are listed here in alphabetical order.
...
@@ -1609,15 +1609,8 @@ available. They are listed here in alphabetical order.
names.
names.
If you simply want to import a module (potentially within a package) by name,
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)
<module 'foo' from ...>
>>> baz = sys.modules[name]
>>> baz
<module 'foo.bar.baz' from ...>
.. versionchanged:: 2.5
.. versionchanged:: 2.5
The level parameter was added.
The level parameter was added.
...
...
Python/bltinmodule.c
View file @
59488d23
...
@@ -53,8 +53,12 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
...
@@ -53,8 +53,12 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR
(
import_doc
,
PyDoc_STRVAR
(
import_doc
,
"__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module
\n
\
"__import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module
\n
\
\n
\
\n
\
Import a module. The globals are only used to determine the context;
\n
\
Import a module. Because this function is meant for use by the Python
\n
\
they are not modified. The locals are currently unused. The fromlist
\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
\
should be a list of names to emulate ``from name import ...'', or an
\n
\
empty list to emulate ``import name''.
\n
\
empty list to emulate ``import name''.
\n
\
When importing a module from a package, note that __import__('A.B', ...)
\n
\
When importing a module from a package, note that __import__('A.B', ...)
\n
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment