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
e29de441
Commit
e29de441
authored
Jan 10, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated eval(), added execfile()
parent
5772ee36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
20 deletions
+56
-20
Doc/lib/libfuncs.tex
Doc/lib/libfuncs.tex
+28
-10
Doc/libfuncs.tex
Doc/libfuncs.tex
+28
-10
No files found.
Doc/lib/libfuncs.tex
View file @
e29de441
...
...
@@ -87,16 +87,16 @@ exactly one argument.)
\code
{
(math.floor(
\var
{
a
}
/
\var
{
b
}
),
\var
{
a
}
\%
{}
\var
{
b
}
)
}
.
\end{funcdesc}
\begin{funcdesc}
{
eval
}{
s
\optional
{
\,
globals
\optional
{
\,
locals
}}}
\begin{funcdesc}
{
eval
}{
expression
\optional
{
\,
globals
\optional
{
\,
locals
}}}
The arguments are a string and two optional dictionaries. The
string argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the dictionaries as
global and local name space. The string must not contain null bytes
or newline characters. The return value is the
result of the expression. If the third argument is omitted it
defaults to the second. If both dictionaries are omitted, the
\var
{
expression
}
argument is parsed and evaluated as a Python
expression (technically speaking, a condition list) using the
\var
{
globals
}
and
\var
{
locals
}
dictionaries as global and local name
space. If the
\var
{
globals
}
dictionary is omitted it defaults to
the
\var
{
locals
}
dictionary. If both dictionaries are omitted, the
expression is executed in the environment where
\code
{
eval
}
is
called. Syntax errors are reported as exceptions. Example:
called. The return value is the result of the evaluated expression.
Syntax errors are reported as exceptions. Example:
\bcode
\begin{verbatim}
>>> x = 1
...
...
@@ -111,8 +111,26 @@ exactly one argument.)
passing
\code
{
'eval'
}
to the
\var
{
kind
}
argument.
Note: dynamic execution of statements is supported by the
\code
{
exec
}
statement.
\code
{
exec
}
statement. Execution of statements from a file is
supported by the
\code
{
execfile()
}
function.
\end{funcdesc}
\begin{funcdesc}
{
execfile
}{
file
\optional
{
\,
globals
\optional
{
\,
locals
}}}
This function is similar to the
\code
{
eval()
}
function or the
\code
{
exec
}
statement, but parses a file instead of a string. It is
different from the
\code
{
import
}
statement in that it does not use
the module administration -- it reads the file unconditionally and
does not create a new module.
The arguments are a file name and two optional dictionaries. The
file is parsed and evaluated as a sequence of Python statements
(similarly to a module) using the
\var
{
globals
}
and
\var
{
locals
}
dictionaries as global and local name space. If the
\var
{
globals
}
dictionary is omitted it defaults to the
\var
{
locals
}
dictionary.
If both dictionaries are omitted, the expression is executed in the
environment where
\code
{
execfile
}
is called. The return value is
None.
\end{funcdesc}
\begin{funcdesc}
{
filter
}{
function
\,
list
}
...
...
Doc/libfuncs.tex
View file @
e29de441
...
...
@@ -87,16 +87,16 @@ exactly one argument.)
\code
{
(math.floor(
\var
{
a
}
/
\var
{
b
}
),
\var
{
a
}
\%
{}
\var
{
b
}
)
}
.
\end{funcdesc}
\begin{funcdesc}
{
eval
}{
s
\optional
{
\,
globals
\optional
{
\,
locals
}}}
\begin{funcdesc}
{
eval
}{
expression
\optional
{
\,
globals
\optional
{
\,
locals
}}}
The arguments are a string and two optional dictionaries. The
string argument is parsed and evaluated as a Python expression
(technically speaking, a condition list) using the dictionaries as
global and local name space. The string must not contain null bytes
or newline characters. The return value is the
result of the expression. If the third argument is omitted it
defaults to the second. If both dictionaries are omitted, the
\var
{
expression
}
argument is parsed and evaluated as a Python
expression (technically speaking, a condition list) using the
\var
{
globals
}
and
\var
{
locals
}
dictionaries as global and local name
space. If the
\var
{
globals
}
dictionary is omitted it defaults to
the
\var
{
locals
}
dictionary. If both dictionaries are omitted, the
expression is executed in the environment where
\code
{
eval
}
is
called. Syntax errors are reported as exceptions. Example:
called. The return value is the result of the evaluated expression.
Syntax errors are reported as exceptions. Example:
\bcode
\begin{verbatim}
>>> x = 1
...
...
@@ -111,8 +111,26 @@ exactly one argument.)
passing
\code
{
'eval'
}
to the
\var
{
kind
}
argument.
Note: dynamic execution of statements is supported by the
\code
{
exec
}
statement.
\code
{
exec
}
statement. Execution of statements from a file is
supported by the
\code
{
execfile()
}
function.
\end{funcdesc}
\begin{funcdesc}
{
execfile
}{
file
\optional
{
\,
globals
\optional
{
\,
locals
}}}
This function is similar to the
\code
{
eval()
}
function or the
\code
{
exec
}
statement, but parses a file instead of a string. It is
different from the
\code
{
import
}
statement in that it does not use
the module administration -- it reads the file unconditionally and
does not create a new module.
The arguments are a file name and two optional dictionaries. The
file is parsed and evaluated as a sequence of Python statements
(similarly to a module) using the
\var
{
globals
}
and
\var
{
locals
}
dictionaries as global and local name space. If the
\var
{
globals
}
dictionary is omitted it defaults to the
\var
{
locals
}
dictionary.
If both dictionaries are omitted, the expression is executed in the
environment where
\code
{
execfile
}
is called. The return value is
None.
\end{funcdesc}
\begin{funcdesc}
{
filter
}{
function
\,
list
}
...
...
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