mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Moved author and date to boilerplate.tex.
Added copyright.tex to all files. Added descr of check_interval to libsys.tex. Corrected lotsa typos in tut.tex (thanks to George M. Sipe). Corrected mktuple (should be newtupleobject) example in ext.tex.
This commit is contained in:
parent
d8336c2286
commit
16cd7f9f12
14 changed files with 132 additions and 90 deletions
8
Doc/boilerplate.tex
Normal file
8
Doc/boilerplate.tex
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
\author{
|
||||||
|
Guido van Rossum \\
|
||||||
|
Dept. CST, CWI, P.O. Box 94079 \\
|
||||||
|
1090 GB Amsterdam, The Netherlands \\
|
||||||
|
E-mail: {\tt guido@cwi.nl}
|
||||||
|
}
|
||||||
|
|
||||||
|
\date{6 Oct 1994 \\ Release 1.1} % XXX update before release!
|
22
Doc/copyright.tex
Normal file
22
Doc/copyright.tex
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||||
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
All Rights Reserved
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the names of Stichting Mathematisch
|
||||||
|
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||||
|
distribution of the software without specific, written prior permission.
|
||||||
|
|
||||||
|
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||||
|
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||||
|
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||||
|
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
13
Doc/ext.tex
13
Doc/ext.tex
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Extending and Embedding the Python Interpreter}
|
\title{Extending and Embedding the Python Interpreter}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
% Tell \index to actually write the .idx file
|
% Tell \index to actually write the .idx file
|
||||||
\makeindex
|
\makeindex
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
@ -427,7 +422,7 @@ arguments, you must pass an empty tuple. For example:
|
||||||
object *result;
|
object *result;
|
||||||
...
|
...
|
||||||
/* Time to call the callback */
|
/* Time to call the callback */
|
||||||
arglist = mktuple(0);
|
arglist = newtupleobject(0);
|
||||||
result = call_object(my_callback, arglist);
|
result = call_object(my_callback, arglist);
|
||||||
DECREF(arglist);
|
DECREF(arglist);
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Extending and Embedding the Python Interpreter}
|
\title{Extending and Embedding the Python Interpreter}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
% Tell \index to actually write the .idx file
|
% Tell \index to actually write the .idx file
|
||||||
\makeindex
|
\makeindex
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
@ -427,7 +422,7 @@ arguments, you must pass an empty tuple. For example:
|
||||||
object *result;
|
object *result;
|
||||||
...
|
...
|
||||||
/* Time to call the callback */
|
/* Time to call the callback */
|
||||||
arglist = mktuple(0);
|
arglist = newtupleobject(0);
|
||||||
result = call_object(my_callback, arglist);
|
result = call_object(my_callback, arglist);
|
||||||
DECREF(arglist);
|
DECREF(arglist);
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
11
Doc/lib.tex
11
Doc/lib.tex
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Library Reference}
|
\title{Python Library Reference}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
\makeindex % tell \index to actually write the .idx file
|
\makeindex % tell \index to actually write the .idx file
|
||||||
|
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Library Reference}
|
\title{Python Library Reference}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
\makeindex % tell \index to actually write the .idx file
|
\makeindex % tell \index to actually write the .idx file
|
||||||
|
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
|
|
@ -20,6 +20,15 @@ It is always available.
|
||||||
modules.)
|
modules.)
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
\begin{datadesc}{check_interval}
|
||||||
|
When this variable is set to an integer value, it determines how often
|
||||||
|
the interpreter checks for periodic things such as thread switches and
|
||||||
|
signal handlers. The default is 10, meaning the check is performed
|
||||||
|
every 10 Python virtual instructions. Setting this to a large value
|
||||||
|
may increase performance for programs using threads. Setting it to a
|
||||||
|
value <= 0 checks every virtual instruction, maximizing responsiveness
|
||||||
|
as well as overhead.
|
||||||
|
|
||||||
\begin{datadesc}{exc_type}
|
\begin{datadesc}{exc_type}
|
||||||
\dataline{exc_value}
|
\dataline{exc_value}
|
||||||
\dataline{exc_traceback}
|
\dataline{exc_traceback}
|
||||||
|
|
|
@ -20,6 +20,15 @@ It is always available.
|
||||||
modules.)
|
modules.)
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
|
\begin{datadesc}{check_interval}
|
||||||
|
When this variable is set to an integer value, it determines how often
|
||||||
|
the interpreter checks for periodic things such as thread switches and
|
||||||
|
signal handlers. The default is 10, meaning the check is performed
|
||||||
|
every 10 Python virtual instructions. Setting this to a large value
|
||||||
|
may increase performance for programs using threads. Setting it to a
|
||||||
|
value <= 0 checks every virtual instruction, maximizing responsiveness
|
||||||
|
as well as overhead.
|
||||||
|
|
||||||
\begin{datadesc}{exc_type}
|
\begin{datadesc}{exc_type}
|
||||||
\dataline{exc_value}
|
\dataline{exc_value}
|
||||||
\dataline{exc_traceback}
|
\dataline{exc_traceback}
|
||||||
|
|
11
Doc/ref.tex
11
Doc/ref.tex
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Reference Manual}
|
\title{Python Reference Manual}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
% Tell \index to actually write the .idx file
|
% Tell \index to actually write the .idx file
|
||||||
\makeindex
|
\makeindex
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Reference Manual}
|
\title{Python Reference Manual}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
% Tell \index to actually write the .idx file
|
% Tell \index to actually write the .idx file
|
||||||
\makeindex
|
\makeindex
|
||||||
|
@ -20,6 +13,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
|
8
Doc/texinputs/boilerplate.tex
Normal file
8
Doc/texinputs/boilerplate.tex
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
\author{
|
||||||
|
Guido van Rossum \\
|
||||||
|
Dept. CST, CWI, P.O. Box 94079 \\
|
||||||
|
1090 GB Amsterdam, The Netherlands \\
|
||||||
|
E-mail: {\tt guido@cwi.nl}
|
||||||
|
}
|
||||||
|
|
||||||
|
\date{6 Oct 1994 \\ Release 1.1} % XXX update before release!
|
22
Doc/texinputs/copyright.tex
Normal file
22
Doc/texinputs/copyright.tex
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||||
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
|
\begin{center}
|
||||||
|
All Rights Reserved
|
||||||
|
\end{center}
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the names of Stichting Mathematisch
|
||||||
|
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||||
|
distribution of the software without specific, written prior permission.
|
||||||
|
|
||||||
|
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||||
|
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||||
|
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||||
|
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
37
Doc/tut.tex
37
Doc/tut.tex
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Tutorial}
|
\title{Python Tutorial}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
|
|
||||||
|
@ -17,6 +10,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
@ -791,7 +786,7 @@ assignments take place.
|
||||||
|
|
||||||
\item
|
\item
|
||||||
The {\tt while} loop executes as long as the condition (here: {\tt b <
|
The {\tt while} loop executes as long as the condition (here: {\tt b <
|
||||||
100}) remains true. In Python, like in C, any non-zero integer value is
|
10}) remains true. In Python, like in C, any non-zero integer value is
|
||||||
true; zero is false. The condition may also be a string or list value,
|
true; zero is false. The condition may also be a string or list value,
|
||||||
in fact any sequence; anything with a non-zero length is true, empty
|
in fact any sequence; anything with a non-zero length is true, empty
|
||||||
sequences are false. The test used in the example is a simple
|
sequences are false. The test used in the example is a simple
|
||||||
|
@ -813,7 +808,7 @@ line).
|
||||||
The {\tt print} statement writes the value of the expression(s) it is
|
The {\tt print} statement writes the value of the expression(s) it is
|
||||||
given. It differs from just writing the expression you want to write
|
given. It differs from just writing the expression you want to write
|
||||||
(as we did earlier in the calculator examples) in the way it handles
|
(as we did earlier in the calculator examples) in the way it handles
|
||||||
multiple expressions and strings. Strings are written without quotes,
|
multiple expressions and strings. Strings are printed without quotes,
|
||||||
and a space is inserted between items, so you can format things nicely,
|
and a space is inserted between items, so you can format things nicely,
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
|
@ -1007,7 +1002,7 @@ arbitrary boundary:
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
>>> def fib(n): # write Fibonacci series up to n
|
>>> def fib(n): # write Fibonacci series up to n
|
||||||
... a, b = 0, 1
|
... a, b = 0, 1
|
||||||
... while b <= n:
|
... while b < n:
|
||||||
... print b,
|
... print b,
|
||||||
... a, b = b, a+b
|
... a, b = b, a+b
|
||||||
...
|
...
|
||||||
|
@ -1084,7 +1079,7 @@ the Fibonacci series, instead of printing it:
|
||||||
>>> def fib2(n): # return Fibonacci series up to n
|
>>> def fib2(n): # return Fibonacci series up to n
|
||||||
... result = []
|
... result = []
|
||||||
... a, b = 0, 1
|
... a, b = 0, 1
|
||||||
... while b <= n:
|
... while b < n:
|
||||||
... result.append(b) # see below
|
... result.append(b) # see below
|
||||||
... a, b = b, a+b
|
... a, b = b, a+b
|
||||||
... return result
|
... return result
|
||||||
|
@ -1359,7 +1354,7 @@ only matters for mutable objects like lists. All comparison operators
|
||||||
have the same priority, which is lower than that of all numerical
|
have the same priority, which is lower than that of all numerical
|
||||||
operators.
|
operators.
|
||||||
|
|
||||||
Comparisons can be chained: e.g., {\tt a < b = c} tests whether {\tt a}
|
Comparisons can be chained: e.g., {\tt a < b == c} tests whether {\tt a}
|
||||||
is less than {\tt b} and moreover {\tt b} equals {\tt c}.
|
is less than {\tt b} and moreover {\tt b} equals {\tt c}.
|
||||||
|
|
||||||
Comparisons may be combined by the Boolean operators {\tt and} and {\tt
|
Comparisons may be combined by the Boolean operators {\tt and} and {\tt
|
||||||
|
@ -1460,14 +1455,14 @@ with the following contents:
|
||||||
|
|
||||||
def fib(n): # write Fibonacci series up to n
|
def fib(n): # write Fibonacci series up to n
|
||||||
a, b = 0, 1
|
a, b = 0, 1
|
||||||
while b <= n:
|
while b < n:
|
||||||
print b,
|
print b,
|
||||||
a, b = b, a+b
|
a, b = b, a+b
|
||||||
|
|
||||||
def fib2(n): # return Fibonacci series up to n
|
def fib2(n): # return Fibonacci series up to n
|
||||||
result = []
|
result = []
|
||||||
a, b = 0, 1
|
a, b = 0, 1
|
||||||
while b <= n:
|
while b < n:
|
||||||
result.append(b)
|
result.append(b)
|
||||||
a, b = b, a+b
|
a, b = b, a+b
|
||||||
return result
|
return result
|
||||||
|
@ -2101,7 +2096,7 @@ may change in the future. Examples of name spaces are: the set of
|
||||||
built-in names (functions such as \verb\abs()\, and built-in exception
|
built-in names (functions such as \verb\abs()\, and built-in exception
|
||||||
names); the global names in a module; and the local names in a
|
names); the global names in a module; and the local names in a
|
||||||
function invocation. In a sense the set of attributes of an object
|
function invocation. In a sense the set of attributes of an object
|
||||||
also form a name space. The important things to know about name
|
also form a name space. The important thing to know about name
|
||||||
spaces is that there is absolutely no relation between names in
|
spaces is that there is absolutely no relation between names in
|
||||||
different name spaces; for instance, two different modules may both
|
different name spaces; for instance, two different modules may both
|
||||||
define a function ``maximize'' without confusion --- users of the
|
define a function ``maximize'' without confusion --- users of the
|
||||||
|
@ -2162,7 +2157,7 @@ names, and the outermost scope (searched last) is the name space
|
||||||
containing built-in names.
|
containing built-in names.
|
||||||
|
|
||||||
Usually, the local scope references the local names of the (textually)
|
Usually, the local scope references the local names of the (textually)
|
||||||
current function. Outside functions, the the local scope references
|
current function. Outside of functions, the the local scope references
|
||||||
the same name space as the global scope: the module's name space.
|
the same name space as the global scope: the module's name space.
|
||||||
Class definitions place yet another name space in the local scope.
|
Class definitions place yet another name space in the local scope.
|
||||||
|
|
||||||
|
@ -2643,7 +2638,7 @@ Python is an evolving language. Since this tutorial was last
|
||||||
thoroughly revised, several new features have been added to the
|
thoroughly revised, several new features have been added to the
|
||||||
language. While ideally I should revise the tutorial to incorporate
|
language. While ideally I should revise the tutorial to incorporate
|
||||||
them in the mainline of the text, lack of time currently requires me
|
them in the mainline of the text, lack of time currently requires me
|
||||||
to follow a more modest approach. In this chapter I will briefly list the
|
to take a more modest approach. In this chapter I will briefly list the
|
||||||
most important improvements to the language and how you can use them
|
most important improvements to the language and how you can use them
|
||||||
to your benefit.
|
to your benefit.
|
||||||
|
|
||||||
|
@ -2984,7 +2979,9 @@ Reference for a full description.
|
||||||
\section{Generalized Dictionaries}
|
\section{Generalized Dictionaries}
|
||||||
|
|
||||||
The keys of dictionaries are no longer restricted to strings -- they
|
The keys of dictionaries are no longer restricted to strings -- they
|
||||||
can be numbers, tuples, or (certain) class instances. (Lists and
|
can be
|
||||||
|
any immutable basic type including strings,
|
||||||
|
numbers, tuples, or (certain) class instances. (Lists and
|
||||||
dictionaries are not acceptable as dictionary keys, in order to avoid
|
dictionaries are not acceptable as dictionary keys, in order to avoid
|
||||||
problems when the object used as a key is modified.)
|
problems when the object used as a key is modified.)
|
||||||
|
|
||||||
|
@ -3007,7 +3004,7 @@ operations are slow for large dictionaries. Examples:
|
||||||
\section{Miscellaneous New Built-in Functions}
|
\section{Miscellaneous New Built-in Functions}
|
||||||
|
|
||||||
The function \verb\vars()\ returns a dictionary containing the current
|
The function \verb\vars()\ returns a dictionary containing the current
|
||||||
local variables. With a module as argument, it returns that module's
|
local variables. With a module argument, it returns that module's
|
||||||
global variables. The old function \verb\dir(x)\ returns
|
global variables. The old function \verb\dir(x)\ returns
|
||||||
\verb\vars(x).keys()\.
|
\verb\vars(x).keys()\.
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
\title{Python Tutorial}
|
\title{Python Tutorial}
|
||||||
|
|
||||||
\author{
|
\input{boilerplate}
|
||||||
Guido van Rossum \\
|
|
||||||
Dept. CST, CWI, P.O. Box 94079 \\
|
|
||||||
1090 GB Amsterdam, The Netherlands \\
|
|
||||||
E-mail: {\tt guido@cwi.nl}
|
|
||||||
}
|
|
||||||
|
|
||||||
\date{14 July 1994 \\ Release 1.0.3} % XXX update before release!
|
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
|
|
||||||
|
@ -17,6 +10,8 @@
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
|
\input{copyright}
|
||||||
|
|
||||||
\begin{abstract}
|
\begin{abstract}
|
||||||
|
|
||||||
\noindent
|
\noindent
|
||||||
|
@ -791,7 +786,7 @@ assignments take place.
|
||||||
|
|
||||||
\item
|
\item
|
||||||
The {\tt while} loop executes as long as the condition (here: {\tt b <
|
The {\tt while} loop executes as long as the condition (here: {\tt b <
|
||||||
100}) remains true. In Python, like in C, any non-zero integer value is
|
10}) remains true. In Python, like in C, any non-zero integer value is
|
||||||
true; zero is false. The condition may also be a string or list value,
|
true; zero is false. The condition may also be a string or list value,
|
||||||
in fact any sequence; anything with a non-zero length is true, empty
|
in fact any sequence; anything with a non-zero length is true, empty
|
||||||
sequences are false. The test used in the example is a simple
|
sequences are false. The test used in the example is a simple
|
||||||
|
@ -813,7 +808,7 @@ line).
|
||||||
The {\tt print} statement writes the value of the expression(s) it is
|
The {\tt print} statement writes the value of the expression(s) it is
|
||||||
given. It differs from just writing the expression you want to write
|
given. It differs from just writing the expression you want to write
|
||||||
(as we did earlier in the calculator examples) in the way it handles
|
(as we did earlier in the calculator examples) in the way it handles
|
||||||
multiple expressions and strings. Strings are written without quotes,
|
multiple expressions and strings. Strings are printed without quotes,
|
||||||
and a space is inserted between items, so you can format things nicely,
|
and a space is inserted between items, so you can format things nicely,
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
|
@ -1007,7 +1002,7 @@ arbitrary boundary:
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
>>> def fib(n): # write Fibonacci series up to n
|
>>> def fib(n): # write Fibonacci series up to n
|
||||||
... a, b = 0, 1
|
... a, b = 0, 1
|
||||||
... while b <= n:
|
... while b < n:
|
||||||
... print b,
|
... print b,
|
||||||
... a, b = b, a+b
|
... a, b = b, a+b
|
||||||
...
|
...
|
||||||
|
@ -1084,7 +1079,7 @@ the Fibonacci series, instead of printing it:
|
||||||
>>> def fib2(n): # return Fibonacci series up to n
|
>>> def fib2(n): # return Fibonacci series up to n
|
||||||
... result = []
|
... result = []
|
||||||
... a, b = 0, 1
|
... a, b = 0, 1
|
||||||
... while b <= n:
|
... while b < n:
|
||||||
... result.append(b) # see below
|
... result.append(b) # see below
|
||||||
... a, b = b, a+b
|
... a, b = b, a+b
|
||||||
... return result
|
... return result
|
||||||
|
@ -1359,7 +1354,7 @@ only matters for mutable objects like lists. All comparison operators
|
||||||
have the same priority, which is lower than that of all numerical
|
have the same priority, which is lower than that of all numerical
|
||||||
operators.
|
operators.
|
||||||
|
|
||||||
Comparisons can be chained: e.g., {\tt a < b = c} tests whether {\tt a}
|
Comparisons can be chained: e.g., {\tt a < b == c} tests whether {\tt a}
|
||||||
is less than {\tt b} and moreover {\tt b} equals {\tt c}.
|
is less than {\tt b} and moreover {\tt b} equals {\tt c}.
|
||||||
|
|
||||||
Comparisons may be combined by the Boolean operators {\tt and} and {\tt
|
Comparisons may be combined by the Boolean operators {\tt and} and {\tt
|
||||||
|
@ -1460,14 +1455,14 @@ with the following contents:
|
||||||
|
|
||||||
def fib(n): # write Fibonacci series up to n
|
def fib(n): # write Fibonacci series up to n
|
||||||
a, b = 0, 1
|
a, b = 0, 1
|
||||||
while b <= n:
|
while b < n:
|
||||||
print b,
|
print b,
|
||||||
a, b = b, a+b
|
a, b = b, a+b
|
||||||
|
|
||||||
def fib2(n): # return Fibonacci series up to n
|
def fib2(n): # return Fibonacci series up to n
|
||||||
result = []
|
result = []
|
||||||
a, b = 0, 1
|
a, b = 0, 1
|
||||||
while b <= n:
|
while b < n:
|
||||||
result.append(b)
|
result.append(b)
|
||||||
a, b = b, a+b
|
a, b = b, a+b
|
||||||
return result
|
return result
|
||||||
|
@ -2101,7 +2096,7 @@ may change in the future. Examples of name spaces are: the set of
|
||||||
built-in names (functions such as \verb\abs()\, and built-in exception
|
built-in names (functions such as \verb\abs()\, and built-in exception
|
||||||
names); the global names in a module; and the local names in a
|
names); the global names in a module; and the local names in a
|
||||||
function invocation. In a sense the set of attributes of an object
|
function invocation. In a sense the set of attributes of an object
|
||||||
also form a name space. The important things to know about name
|
also form a name space. The important thing to know about name
|
||||||
spaces is that there is absolutely no relation between names in
|
spaces is that there is absolutely no relation between names in
|
||||||
different name spaces; for instance, two different modules may both
|
different name spaces; for instance, two different modules may both
|
||||||
define a function ``maximize'' without confusion --- users of the
|
define a function ``maximize'' without confusion --- users of the
|
||||||
|
@ -2162,7 +2157,7 @@ names, and the outermost scope (searched last) is the name space
|
||||||
containing built-in names.
|
containing built-in names.
|
||||||
|
|
||||||
Usually, the local scope references the local names of the (textually)
|
Usually, the local scope references the local names of the (textually)
|
||||||
current function. Outside functions, the the local scope references
|
current function. Outside of functions, the the local scope references
|
||||||
the same name space as the global scope: the module's name space.
|
the same name space as the global scope: the module's name space.
|
||||||
Class definitions place yet another name space in the local scope.
|
Class definitions place yet another name space in the local scope.
|
||||||
|
|
||||||
|
@ -2643,7 +2638,7 @@ Python is an evolving language. Since this tutorial was last
|
||||||
thoroughly revised, several new features have been added to the
|
thoroughly revised, several new features have been added to the
|
||||||
language. While ideally I should revise the tutorial to incorporate
|
language. While ideally I should revise the tutorial to incorporate
|
||||||
them in the mainline of the text, lack of time currently requires me
|
them in the mainline of the text, lack of time currently requires me
|
||||||
to follow a more modest approach. In this chapter I will briefly list the
|
to take a more modest approach. In this chapter I will briefly list the
|
||||||
most important improvements to the language and how you can use them
|
most important improvements to the language and how you can use them
|
||||||
to your benefit.
|
to your benefit.
|
||||||
|
|
||||||
|
@ -2984,7 +2979,9 @@ Reference for a full description.
|
||||||
\section{Generalized Dictionaries}
|
\section{Generalized Dictionaries}
|
||||||
|
|
||||||
The keys of dictionaries are no longer restricted to strings -- they
|
The keys of dictionaries are no longer restricted to strings -- they
|
||||||
can be numbers, tuples, or (certain) class instances. (Lists and
|
can be
|
||||||
|
any immutable basic type including strings,
|
||||||
|
numbers, tuples, or (certain) class instances. (Lists and
|
||||||
dictionaries are not acceptable as dictionary keys, in order to avoid
|
dictionaries are not acceptable as dictionary keys, in order to avoid
|
||||||
problems when the object used as a key is modified.)
|
problems when the object used as a key is modified.)
|
||||||
|
|
||||||
|
@ -3007,7 +3004,7 @@ operations are slow for large dictionaries. Examples:
|
||||||
\section{Miscellaneous New Built-in Functions}
|
\section{Miscellaneous New Built-in Functions}
|
||||||
|
|
||||||
The function \verb\vars()\ returns a dictionary containing the current
|
The function \verb\vars()\ returns a dictionary containing the current
|
||||||
local variables. With a module as argument, it returns that module's
|
local variables. With a module argument, it returns that module's
|
||||||
global variables. The old function \verb\dir(x)\ returns
|
global variables. The old function \verb\dir(x)\ returns
|
||||||
\verb\vars(x).keys()\.
|
\verb\vars(x).keys()\.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue