Kaydet (Commit) 4bd023f8 authored tarafından Guido van Rossum's avatar Guido van Rossum

* lib3.tex (module string): added rindex().

* lib1.tex (section{Built-in Functions}): added bagof(), lambda(), map()
  and reduce().  Repharased apply().  Removed or rephrased references to
  exec() (now the exec stmt).
* lib4.tex: posix.exec --> posix.execv
* ref4.tex, ref8.tex, tut.tex: builtin --> __builtin__
* lib3.tex (module string): added atof() and atol(), and ato[fl]_error.
üst 3b716046
...@@ -19,8 +19,9 @@ part of their execution, e.g. by invoking (calling) a function. ...@@ -19,8 +19,9 @@ part of their execution, e.g. by invoking (calling) a function.
The following are code blocks: A module is a code block. A function The following are code blocks: A module is a code block. A function
body is a code block. A class definition is a code block. Each body is a code block. A class definition is a code block. Each
command typed interactively is a separate code block; a script file is command typed interactively is a separate code block; a script file is
a code block. The string argument passed to the built-in functions a code block. The string argument passed to the built-in function
\verb\eval\ and \verb\exec\ are code blocks. And finally, the \verb\eval\ and to the \verb\exec\ statement are code blocks.
And finally, the
expression read and evaluated by the built-in function \verb\input\ is expression read and evaluated by the built-in function \verb\input\ is
a code block. a code block.
...@@ -66,7 +67,7 @@ assignment, \verb\for\ loop header, or \verb\except\ clause header. ...@@ -66,7 +67,7 @@ assignment, \verb\for\ loop header, or \verb\except\ clause header.
When a global name is not found in the global name space, it is When a global name is not found in the global name space, it is
searched in the list of ``built-in'' names (which is actually the searched in the list of ``built-in'' names (which is actually the
global name space of the module \verb\builtin\). When a name is not global name space of the module \verb\__builtin__\). When a name is not
found at all, the \verb\NameError\ exception is raised. found at all, the \verb\NameError\ exception is raised.
The following table lists the meaning of the local and global name The following table lists the meaning of the local and global name
......
...@@ -14,13 +14,13 @@ interpreter is invoked, it is useful to have a notion of a complete ...@@ -14,13 +14,13 @@ interpreter is invoked, it is useful to have a notion of a complete
Python program. A complete Python program is executed in a minimally Python program. A complete Python program is executed in a minimally
initialized environment: all built-in and standard modules are initialized environment: all built-in and standard modules are
available, but none have been initialized, except for \verb\sys\ available, but none have been initialized, except for \verb\sys\
(various system services), \verb\builtin\ (built-in functions, (various system services), \verb\__builtin__\ (built-in functions,
exceptions and \verb\None\) and \verb\__main__\. The latter is used exceptions and \verb\None\) and \verb\__main__\. The latter is used
to provide the local and global name space for execution of the to provide the local and global name space for execution of the
complete program. complete program.
\bimodindex{sys} \bimodindex{sys}
\bimodindex{__main__} \bimodindex{__main__}
\bimodindex{builtin} \bimodindex{__builtin__}
The syntax for a complete Python program is that for file input, The syntax for a complete Python program is that for file input,
described in the next section. described in the next section.
...@@ -58,11 +58,7 @@ This syntax is used in the following situations: ...@@ -58,11 +58,7 @@ This syntax is used in the following situations:
\item when parsing a module; \item when parsing a module;
\item when parsing a string passed to \verb\exec()\; \item when parsing a string passed to the \verb\exec\ statement;
\bifuncindex{exec}
\item when parsing a file passed to \verb\execfile()\;
\bifuncindex{execfile}
\end{itemize} \end{itemize}
......
...@@ -19,8 +19,9 @@ part of their execution, e.g. by invoking (calling) a function. ...@@ -19,8 +19,9 @@ part of their execution, e.g. by invoking (calling) a function.
The following are code blocks: A module is a code block. A function The following are code blocks: A module is a code block. A function
body is a code block. A class definition is a code block. Each body is a code block. A class definition is a code block. Each
command typed interactively is a separate code block; a script file is command typed interactively is a separate code block; a script file is
a code block. The string argument passed to the built-in functions a code block. The string argument passed to the built-in function
\verb\eval\ and \verb\exec\ are code blocks. And finally, the \verb\eval\ and to the \verb\exec\ statement are code blocks.
And finally, the
expression read and evaluated by the built-in function \verb\input\ is expression read and evaluated by the built-in function \verb\input\ is
a code block. a code block.
...@@ -66,7 +67,7 @@ assignment, \verb\for\ loop header, or \verb\except\ clause header. ...@@ -66,7 +67,7 @@ assignment, \verb\for\ loop header, or \verb\except\ clause header.
When a global name is not found in the global name space, it is When a global name is not found in the global name space, it is
searched in the list of ``built-in'' names (which is actually the searched in the list of ``built-in'' names (which is actually the
global name space of the module \verb\builtin\). When a name is not global name space of the module \verb\__builtin__\). When a name is not
found at all, the \verb\NameError\ exception is raised. found at all, the \verb\NameError\ exception is raised.
The following table lists the meaning of the local and global name The following table lists the meaning of the local and global name
......
...@@ -14,13 +14,13 @@ interpreter is invoked, it is useful to have a notion of a complete ...@@ -14,13 +14,13 @@ interpreter is invoked, it is useful to have a notion of a complete
Python program. A complete Python program is executed in a minimally Python program. A complete Python program is executed in a minimally
initialized environment: all built-in and standard modules are initialized environment: all built-in and standard modules are
available, but none have been initialized, except for \verb\sys\ available, but none have been initialized, except for \verb\sys\
(various system services), \verb\builtin\ (built-in functions, (various system services), \verb\__builtin__\ (built-in functions,
exceptions and \verb\None\) and \verb\__main__\. The latter is used exceptions and \verb\None\) and \verb\__main__\. The latter is used
to provide the local and global name space for execution of the to provide the local and global name space for execution of the
complete program. complete program.
\bimodindex{sys} \bimodindex{sys}
\bimodindex{__main__} \bimodindex{__main__}
\bimodindex{builtin} \bimodindex{__builtin__}
The syntax for a complete Python program is that for file input, The syntax for a complete Python program is that for file input,
described in the next section. described in the next section.
...@@ -58,11 +58,7 @@ This syntax is used in the following situations: ...@@ -58,11 +58,7 @@ This syntax is used in the following situations:
\item when parsing a module; \item when parsing a module;
\item when parsing a string passed to \verb\exec()\; \item when parsing a string passed to the \verb\exec\ statement;
\bifuncindex{exec}
\item when parsing a file passed to \verb\execfile()\;
\bifuncindex{execfile}
\end{itemize} \end{itemize}
......
...@@ -1605,15 +1605,19 @@ Note that it lists all types of names: variables, modules, functions, etc. ...@@ -1605,15 +1605,19 @@ Note that it lists all types of names: variables, modules, functions, etc.
{\tt dir()} does not list the names of built-in functions and variables. {\tt dir()} does not list the names of built-in functions and variables.
If you want a list of those, they are defined in the standard module If you want a list of those, they are defined in the standard module
{\tt builtin}: {\tt __builtin__}:
\bcode\begin{verbatim} \bcode\begin{verbatim}
>>> import builtin >>> import __builtin__
>>> dir(builtin) >>> dir(__builtin__)
['EOFError', 'KeyboardInterrupt', 'MemoryError', 'NameError', 'None', 'Runti ['AccessError', 'AttributeError', 'ConflictError', 'EOFError', 'IOError', 'I
meError', 'SystemError', 'TypeError', 'abs', 'chr', 'dir', 'divmod', 'eval', mportError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'MemoryError', '
'exec', 'float', 'input', 'int', 'len', 'long', 'max', 'min', 'open', 'ord' NameError', 'None', 'OverflowError', 'RuntimeError', 'SyntaxError', 'SystemE
, 'pow', 'range', 'raw_input', 'reload', 'type'] rror', 'SystemExit', 'TypeError', 'ValueError', 'ZeroDivisionError', 'abs',
'apply', 'chr', 'cmp', 'coerce', 'compile', 'dir', 'divmod', 'eval', 'execfi
le', 'float', 'getattr', 'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'le
n', 'long', 'max', 'min', 'oct', 'open', 'ord', 'pow', 'range', 'raw_input',
'reload', 'repr', 'round', 'setattr', 'str', 'type']
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
...@@ -2083,8 +2087,7 @@ interpreter quits. The statements executed by the top-level ...@@ -2083,8 +2087,7 @@ interpreter quits. The statements executed by the top-level
invocation of the interpreter, either read from a script file or invocation of the interpreter, either read from a script file or
interactively, are considered part of a module called \verb\__main__\, interactively, are considered part of a module called \verb\__main__\,
so they have their own global name space. (The built-in names so they have their own global name space. (The built-in names
actually also live in a module; this is called \verb\builtin\, actually also live in a module; this is called \verb\__builtin__\.)
although it should really have been called \verb\__builtin__\.)
The local name space for a function is created when the function is The local name space for a function is created when the function is
called, and deleted when the function returns or raises an exception called, and deleted when the function returns or raises an exception
......
...@@ -1605,15 +1605,19 @@ Note that it lists all types of names: variables, modules, functions, etc. ...@@ -1605,15 +1605,19 @@ Note that it lists all types of names: variables, modules, functions, etc.
{\tt dir()} does not list the names of built-in functions and variables. {\tt dir()} does not list the names of built-in functions and variables.
If you want a list of those, they are defined in the standard module If you want a list of those, they are defined in the standard module
{\tt builtin}: {\tt __builtin__}:
\bcode\begin{verbatim} \bcode\begin{verbatim}
>>> import builtin >>> import __builtin__
>>> dir(builtin) >>> dir(__builtin__)
['EOFError', 'KeyboardInterrupt', 'MemoryError', 'NameError', 'None', 'Runti ['AccessError', 'AttributeError', 'ConflictError', 'EOFError', 'IOError', 'I
meError', 'SystemError', 'TypeError', 'abs', 'chr', 'dir', 'divmod', 'eval', mportError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'MemoryError', '
'exec', 'float', 'input', 'int', 'len', 'long', 'max', 'min', 'open', 'ord' NameError', 'None', 'OverflowError', 'RuntimeError', 'SyntaxError', 'SystemE
, 'pow', 'range', 'raw_input', 'reload', 'type'] rror', 'SystemExit', 'TypeError', 'ValueError', 'ZeroDivisionError', 'abs',
'apply', 'chr', 'cmp', 'coerce', 'compile', 'dir', 'divmod', 'eval', 'execfi
le', 'float', 'getattr', 'hasattr', 'hash', 'hex', 'id', 'input', 'int', 'le
n', 'long', 'max', 'min', 'oct', 'open', 'ord', 'pow', 'range', 'raw_input',
'reload', 'repr', 'round', 'setattr', 'str', 'type']
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
...@@ -2083,8 +2087,7 @@ interpreter quits. The statements executed by the top-level ...@@ -2083,8 +2087,7 @@ interpreter quits. The statements executed by the top-level
invocation of the interpreter, either read from a script file or invocation of the interpreter, either read from a script file or
interactively, are considered part of a module called \verb\__main__\, interactively, are considered part of a module called \verb\__main__\,
so they have their own global name space. (The built-in names so they have their own global name space. (The built-in names
actually also live in a module; this is called \verb\builtin\, actually also live in a module; this is called \verb\__builtin__\.)
although it should really have been called \verb\__builtin__\.)
The local name space for a function is created when the function is The local name space for a function is created when the function is
called, and deleted when the function returns or raises an exception called, and deleted when the function returns or raises an exception
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment