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
98bcb708
Commit
98bcb708
authored
Mar 24, 2006
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation for PEP 338
parent
c841bb6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
Doc/Makefile.deps
Doc/Makefile.deps
+1
-0
Doc/lib/lib.tex
Doc/lib/lib.tex
+1
-0
Doc/lib/librunpy.tex
Doc/lib/librunpy.tex
+74
-0
No files found.
Doc/Makefile.deps
View file @
98bcb708
...
@@ -126,6 +126,7 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
...
@@ -126,6 +126,7 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
lib/libwarnings.tex
\
lib/libwarnings.tex
\
lib/libimp.tex
\
lib/libimp.tex
\
lib/libzipimport.tex
\
lib/libzipimport.tex
\
lib/librunpy.tex
\
lib/libpkgutil.tex
\
lib/libpkgutil.tex
\
lib/libparser.tex
\
lib/libparser.tex
\
lib/libbltin.tex
\
lib/libbltin.tex
\
...
...
Doc/lib/lib.tex
View file @
98bcb708
...
@@ -394,6 +394,7 @@ and how to embed it in other applications.
...
@@ -394,6 +394,7 @@ and how to embed it in other applications.
\input
{
libzipimport
}
\input
{
libzipimport
}
\input
{
libpkgutil
}
\input
{
libpkgutil
}
\input
{
libmodulefinder
}
\input
{
libmodulefinder
}
\input
{
librunpy
}
% =============
% =============
...
...
Doc/lib/librunpy.tex
0 → 100644
View file @
98bcb708
\section
{
\module
{
runpy
}
---
Locating and executing Python modules.
}
\declaremodule
{
standard
}{
runpy
}
% standard library, in Python
\moduleauthor
{
Nick Coghlan
}{
ncoghlan@gmail.com
}
\modulesynopsis
{
Locate and execute Python modules as scripts
}
\versionadded
{
2.5
}
The
\module
{
runpy
}
module is used to locate and run Python modules
without importing them first. It's main use is to implement the
\programopt
{
-m
}
command line switch that allows scripts to be located
using the Python module namespace rather than the filesystem.
When executed as a script, the module effectively operates as follows:
\begin{verbatim}
del sys.argv[0] # Remove the runpy module from the arguments
run
_
module(sys.argv[0], run
_
name="
__
main
__
", alter
_
sys=True)
\end{verbatim}
The
\module
{
runpy
}
module provides a single function:
\begin{funcdesc}
{
run
_
module
}{
mod
_
name
\optional
{
, init
_
globals
}
\optional
{
, run
_
name
}
\optional
{
, alter
_
sys
}}
Execute the code of the specified module and return the resulting
module globals dictionary. The module's code is first located using
the standard import mechanism (refer to PEP 302 for details) and
then executed in a fresh module namespace.
The optional dictionary argument
\var
{
init
_
globals
}
may be used to
pre-populate the globals dictionary before the code is executed.
The supplied dictionary will not be modified. If any of the special
global variables below are defined in the supplied dictionary, those
definitions are overridden by the
\code
{
run
_
module
}
function.
The special global variables
\code
{__
name
__}
,
\code
{__
file
__}
,
\code
{__
loader
__}
and
\code
{__
builtins
__}
are set in the globals
dictionary before the module code is executed.
\code
{__
name
__}
is set to
\var
{
run
_
name
}
if this optional argument is
supplied, and the
\var
{
mod
_
name
}
argument otherwise.
\code
{__
loader
__}
is set to the PEP 302 module loader used to retrieve
the code for the module (This loader may be a wrapper around the
standard import mechanism).
\code
{__
file
__}
is set to the name provided by the module loader. If
the loader does not make filename information available, this
variable is set to
\code
{
None
}
.
\code
{__
builtins
__}
is automatically initialised with a reference to
the top level namespace of the
\module
{__
builtin
__}
module.
If the argument
\var
{
alter
_
sys
}
is supplied and evaluates to
\code
{
True
}
, then
\code
{
sys.argv[0]
}
is updated with the value of
\code
{__
file
__}
and
\code
{
sys.modules[
__
name
__
]
}
is updated with a
temporary module object for the module being executed. Both
\code
{
sys.argv[0]
}
and
\code
{
sys.modules[
__
name
__
]
}
are restored to
their original values before the function returns.
Note that this manipulation of
\module
{
sys
}
is not thread-safe. Other
threads may see the partially initialised module, as well as the
altered list of arguments. It is recommended that the
\module
{
sys
}
module be left alone when invoking this function from threaded code.
\end{funcdesc}
\begin{seealso}
\seepep
{
338
}{
Executing modules as scripts
}{
PEP written and
implemented by Nick Coghlan.
}
\end{seealso}
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