Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a05f95

Browse files
committed
Got rid of most XXXes in the News chapter. Bumped the version to 1.4.
1 parent fd1e543 commit 6a05f95

2 files changed

Lines changed: 268 additions & 152 deletions

File tree

Doc/tut.tex

Lines changed: 134 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ \subsection{Interactive Mode}
215215

216216
\bcode\begin{verbatim}
217217
python
218-
Python 1.4b3 (Aug 25 1996) [GCC 2.7.0]
218+
Python 1.4 (Oct 25 1996) [GCC 2.7.2]
219219
Copyright 1991-1996 Stichting Mathematisch Centrum, Amsterdam
220220
>>>
221221
\end{verbatim}\ecode
@@ -1850,7 +1850,7 @@ \section{Exceptions}
18501850
In general it contains a stack backtrace listing source lines; however,
18511851
it will not display lines read from standard input.
18521852

1853-
The Python library reference manual lists the built-in exceptions and
1853+
The Python Library Reference Manual lists the built-in exceptions and
18541854
their meanings.
18551855

18561856
\section{Handling Exceptions}
@@ -3482,7 +3482,7 @@ \section{Customizing Import and Built-Ins}
34823482
provides the default implementation, but more interesting, the various
34833483
steps it takes are available separately from the new built-in module
34843484
\code{imp}. (See the section on \code{imp} in the Library Reference
3485-
Manual for more information on this module -- it also contains a
3485+
Manual for more information on this module --- it also contains a
34863486
complete example of how to write your own \code{__import__} function.)
34873487

34883488
When you do \code{dir()} in a fresh interactive interpreter you will
@@ -3580,7 +3580,7 @@ \section{Keyword Arguments}
35803580
positional arguments followed by zero or more keyword arguments, where
35813581
the keywords must be chosen from the formal parameter names. It's not
35823582
important whether a formal parameter has a default value or not. No
3583-
argument must receive a value more than once -- formal parameter names
3583+
argument must receive a value more than once --- formal parameter names
35843584
corresponding to positional arguments cannot be used as keywords in
35853585
the same calls.
35863586

@@ -3657,7 +3657,7 @@ \section{Keyword Arguments}
36573657

36583658
\item
36593659
In the effort of implementing keyword arguments, function and
3660-
especially method calls have been sped up significantly -- for a
3660+
especially method calls have been sped up significantly --- for a
36613661
method with ten formal parameters, the call overhead has been cut in
36623662
half; for a function with one formal parameters, the overhead has been
36633663
reduced by a third.
@@ -3874,8 +3874,10 @@ \chapter{New in Release 1.4}
38743874
This chapter describes the major additions to the Python language and
38753875
library in version 1.4. Many minor changes are not listed here;
38763876
it is recommended to read the file \code{Misc/NEWS} in the Python
3877-
source distribution for a complete listing of all changes, however
3878-
small.
3877+
source distribution for a complete listing of changes. In particular,
3878+
changes that only affect C programmers or the build and installation
3879+
process are not described in this chapter (the new installation
3880+
lay-out is explained below under \code{sys.prefix} though).
38793881

38803882
\begin{itemize}
38813883

@@ -3887,34 +3889,35 @@ \chapter{New in Release 1.4}
38873889
\code{x**(y**z)}, and \code{-x**y} is \code{-(x**y)}.
38883890

38893891
\item
3890-
Complex numbers. Imaginary literals are writen with a \code{'j'}
3891-
suffix (\code{'J'} is allowed as well.) Complex numbers with a nonzero
3892-
real component are written as \code{(\var{real}+\var{imag}j)}. You
3893-
can also use the new built-in function \code{complex()} which takes
3894-
one or two arguments: \code{complex(x)} is equivalent to \code{x +
3895-
0j}, and \code{complex(x, y)} is \code{x + y*0j}.
3896-
3897-
The usual arithmetic operators on complex numbers are supported, so
3898-
that e.g. \code{1j**2} equals \code{complex(-1.0)}.
3899-
3900-
To extract the real and imaginary part from a complex number \code{z},
3892+
Complex numbers. Imaginary literals are writen with a \code{'j'}
3893+
suffix (\code{'J'} is allowed as well.) Complex numbers with a nonzero
3894+
real component are written as \code{(\var{real}+\var{imag}j)}. You
3895+
can also use the new built-in function \code{complex()} which takes
3896+
one or two arguments: \code{complex(x)} is equivalent to \code{x +
3897+
0j}, and \code{complex(x, y)} is \code{x + y*0j}. For example,
3898+
\code{1j**2} yields \code{complex(-1.0)} (which is another way of
3899+
saying ``the real value 1.0 represented as a complex number.''
3900+
3901+
Complex numbers are always represented as two floating point numbers,
3902+
the real and imaginary part.
3903+
To extract these parts from a complex number \code{z},
39013904
use \code{z.real} and \code{z.imag}. The conversion functions to
39023905
floating point and integer (\code{float()}, \code{int()} and
3903-
\code{long()}) don't work for complex numbers -- there is no one
3904-
obvious way to convert a complex number to a real number. Use
3906+
\code{long()}) don't work for complex numbers --- there is no one
3907+
correct way to convert a complex number to a real number. Use
39053908
\code{abs(z)} to get its magnitude (as a float) or \code{z.real} to
39063909
get its real part.
39073910

39083911
Module \code{cmath} provides versions of all math functions that take
39093912
complex arguments and return complex results. (Module \code{math}
39103913
only supports real numbers, so that \code{math.sqrt(-1)} still raises
39113914
a \code{ValueError} exception. Numerical experts agree that this is
3912-
the way it shold be.)
3915+
the way it should be.)
39133916

39143917
\item
39153918
New indexing syntax. It is now possible to use a tuple as an indexing
39163919
expression for a mapping object without parenthesizing it,
3917-
e.g. \code{x[1, 2, 3]}.
3920+
e.g. \code{x[1, 2, 3]} is equivalent to \code{x[(1, 2, 3)]}.
39183921

39193922
\item
39203923
New slicing syntax. In support of the Numerical Python extension
@@ -3925,22 +3928,25 @@ \chapter{New in Release 1.4}
39253928
\code{slice(lo, hi, stride)} and a new built-in object
39263929
\code{Ellipses}, which yield the same effect without using special
39273930
syntax. None of the standard sequence types support indexing with
3928-
slice objects or ellipses yet. Note that when any of these extensions
3929-
are used, the mapping interface for indexing will be used.
3931+
slice objects or ellipses yet.
39303932

3931-
When a user-defined class instance is sliced using this extended slice
3932-
notation, its \code{__getitem__} method is invoked -- the
3933+
Note that when this new slicing syntax is used, the mapping interface
3934+
will be used, not the sequence interface. In particular, when a
3935+
user-defined class instance is sliced using this new slicing syntax,
3936+
its \code{__getitem__} method is invoked --- the
39333937
\code{__getslice__} method is only invoked when a single old-style
3934-
slice is used, i.e. \code{x[lo:hi]}, with possible omission or
3938+
slice is used, i.e. \code{x[lo:hi]}, with possible omission of
39353939
\code{lo} and/or \code{hi}. Some examples:
39363940

39373941
\begin{verbatim}
3938-
x[1:2:-3] --> slice(1, 2, -3)
3939-
x[-1:2:] --> slice(-1, 2, None)
3940-
x[::] --> slice(None, None, None)
3941-
x[1, 2:3] --> (1, slice(2, 3, None))
3942-
x[1:2, 3:4] --> (slice(1, 2, None), slice(3, 4, None))
3943-
x[1:2, ..., 3:4] --> (slice(1, 2, None), Ellipses, slice(3, 4, None))
3942+
x[0:10:2] -> slice(0, 10, 2)
3943+
x[:2:] -> slice(None, 2, None)
3944+
x[::-1] -> slice(None, None, -1)
3945+
x[::] -> slice(None, None, None)
3946+
x[1, 2:3] -> (1, slice(2, 3, None))
3947+
x[1:2, 3:4] -> (slice(1, 2, None), slice(3, 4, None))
3948+
x[1:2, ..., 3:4] -> (slice(1, 2, None), Ellipses,
3949+
slice(3, 4, None))
39443950
\end{verbatim}
39453951

39463952
For more help with this you are referred to the matrix-sig.
@@ -3950,84 +3956,135 @@ \chapter{New in Release 1.4}
39503956
longer a reserved word. This saves a few cycles here and there.
39513957

39523958
\item
3953-
There is now limited support for class-private identifiers. Any
3954-
identifier of the form \code{__spam} (two leading underscores, no two
3955-
trailing underscores) is now textually replaced with
3956-
\code{_classname__spam}, where \code{classname} is the current class
3957-
name with leading underscore(s) stripped. This munging is done
3958-
without regard of the syntactic position of the identifier, so it can
3959-
be used to define class-private instance and class variables, methods,
3960-
as well as globals, and even class-private instance variables on
3961-
instances of {\em other} classes. Truncation may occur when the
3962-
munged name would be longer than 255 characters. Outside classes, no
3963-
munging occurs.
3964-
3965-
Name munging is mostly intended to give classes an easy way to define
3966-
``private'' instance variables and methods, without having to worry
3967-
about instance variables defined by derived classes, or mucking with
3968-
instance variables by code outside the class. Note that the munging
3969-
rules are designed mostly to avoid accidents; it still is possible for
3970-
a ``determined soul'' to access or modify a variable that's considered
3971-
private. This can even be useful, e.g. for the debugger, and that's
3972-
one reason why this loophole is not closed. (Buglet: accidental
3973-
derivation of a class with the same name as the base class makes
3959+
Name mangling. There is now limited support for class-private
3960+
identifiers. Any identifier of the form \code{__spam} (at least two
3961+
leading underscores, at most one trailing underscore) is now textually
3962+
replaced with \code{_classname__spam}, where \code{classname} is the
3963+
current class name with leading underscore(s) stripped. This mangling
3964+
is done without regard of the syntactic position of the identifier, so
3965+
it can be used to define class-private instance and class variables,
3966+
methods, as well as globals, and even to store instance variables
3967+
private to this class on instances of {\em other} classes. Truncation
3968+
may occur when the mangled name would be longer than 255 characters.
3969+
Outside classes, or when the class name consists of only underscores,
3970+
no mangling occurs.
3971+
3972+
Name mangling is intended to give classes an easy way to define
3973+
``private'' instance variables and methods, without having to worry
3974+
about instance variables defined by derived classes, or mucking with
3975+
instance variables by code outside the class. Note that the mangling
3976+
rules are designed mostly to avoid accidents; it still is possible for
3977+
a determined soul to access or modify a variable that is considered
3978+
private. This can even be useful, e.g. for the debugger, and that's
3979+
one reason why this loophole is not closed. (Buglet: accidental
3980+
derivation of a class with the same name as the base class makes
39743981
accidental use of private variables of the base class possible.)
39753982

39763983
Notice that code passed to \code{exec}, \code{eval()} or
39773984
\code{evalfile()} does not consider the classname of the invoking
39783985
class to be the current class; this is similar to the effect of the
39793986
\code{global} statement, the effect of which is likewise restricted to
3980-
code that is byte-compiled together.
3987+
code that is byte-compiled together. The same restriction applies to
3988+
\code{getattr()}, \code{setattr()} and \code{delattr()}, as well as
3989+
when referencing \code{__dict__} directly.
3990+
3991+
Here's an example of a class that implements its own
3992+
\code{__getattr__} and \code{__setattr__} methods and stores all
3993+
attributes in a private variable, in a way that works in Python 1.4 as
3994+
well as in previous versions:
3995+
3996+
\begin{verbatim}
3997+
class VirtualAttributes:
3998+
__vdict = None
3999+
__vdict_name = locals().keys()[0]
4000+
4001+
def __init__(self):
4002+
self.__dict__[self.__vdict_name] = {}
4003+
4004+
def __getattr__(self, name):
4005+
return self.__vdict[name]
4006+
4007+
def __setattr__(self, name, value):
4008+
self.__vdict[name] = value
4009+
\end{verbatim}
4010+
39814011

39824012
\item
3983-
Syntax errors detected by the code generation phase of the Python
3984-
bytecode compiler now include a line number. The line number is
3985-
appended in parentheses. It is suppressed if the error occurs
3986-
in line 1 (this usually happens in interactive use).
4013+
Improved syntax error message. Syntax errors detected by the code
4014+
generation phase of the Python bytecode compiler now include a line
4015+
number. The line number is appended in parentheses. It is suppressed
4016+
if the error occurs in line 1 (this usually happens in interactive
4017+
use).
39874018

39884019
\item
4020+
Different exception raised.
39894021
Unrecognized keyword arguments now raise a \code{TypeError} exception
39904022
rather than \code{KeyError}.
39914023

39924024
\item
3993-
A warning is written to sys.stderr when a \code{__del__} method raises
3994-
an exception. Formerly, such exceptions were completely ignored.
3995-
The new behavior, while needed in order to debug failing
4025+
Exceptions in \code{__del__} methods. When a \code{__del__} method
4026+
raises an exception, a warning is written to \code{sys.stderr} and the
4027+
exception is ignored. Formerly, such exceptions were ignored without
4028+
warning. (Propagating the exception is not an option since it it is
4029+
invoked from an object finalizer, which cannot
4030+
) (Buglet: The new behavior, while needed in order to debug failing
39964031
\code{__del__} methods, is occasionally annoying, because if affects
39974032
the program's standard error stream. It honors assignments to
39984033
\code{sys.stderr}, so it can be redirected from within a program if
3999-
desired.
4034+
desired.)
40004035

40014036
\item
40024037
New built-in function \code{list()} converts any sequence to a new list.
40034038
Note that when the argument is a list, the return value is a fresh
40044039
copy, similar to what would be returned by \code{a[:]}.
40054040

40064041
\item
4007-
New built-in module \code{operator}. XXX
4042+
New built-in module \code{operator}. While undocumented, the concept
4043+
is real simply: \code{operator.__add__(x, y)} does exactly the same
4044+
thing as \code{x+y} (for all types --- built-in, user-defined,
4045+
extension-defined). As a convenience, \code{operator.add} does the
4046+
same thing, but beware --- you can't use \code{operator.and} and a few
4047+
others where the ``natural'' name for an operator is a reserved
4048+
keyword. You can add a single trailing underscore in such cases.
40084049

40094050
\item
4010-
New built-in module \code{errno}. XXX
4051+
New built-in module \code{errno}. See the Library Reference Manual.
40114052

40124053
\item
4013-
Rewritten \code{cgi} module. XXX
4054+
Rewritten \code{cgi} module. See the Library Reference Manual.
40144055

40154056
\item
40164057
Improved restricted execution module (\code{rexec}). New module
4017-
\code{Bastion}. XXX
4058+
\code{Bastion}. Both are now documented in a new chapter on
4059+
restricted execution in the Library Reference Manual.
40184060

40194061
\item
4020-
New string operations: lstrip(), rstrip(), capitalize(), capwords(),
4021-
translate(), maketrans(); extended string operation: split(s, sep,
4022-
maxsep). XXX
4062+
New string operations (all described in the Library Reference Manual):
4063+
\code{lstrip()}, \code{rstrip()} (strip only the left/right
4064+
whitespace), \code{capitalize()} (uppercase the first character,
4065+
lowercase the rest), \code{capwords()} (capitalize each word,
4066+
delimited a la \code{string.split()}), \code{translate()} (string
4067+
transliteration -- this existed before but can now also delete
4068+
characters by specifying a third argument), \code{maketrans()} (a
4069+
convenience function for creating translation tables for
4070+
\code{translate()} and \code{regex.compile()}). The string function
4071+
\code{split()} has an optional third argument which specifies the
4072+
maximum number of separators to split;
4073+
e.g. \code{string.split('a=b=c', '=', 1)} yields \code{['a', 'b=c']}.
4074+
(Note that for a long time, \code{split()} and \code{splitfields()}
4075+
are synonyms.
40234076

40244077
\item
4025-
New regsub operations: capwords(), splitx(), and split(s, sep, maxsep).
4026-
XXX
4078+
New regsub operations (see the Library Reference Manual):
4079+
\code{regsub.capwords()} (like \code{string.capwords()} but allows you to
4080+
specify the word delimiter as a regular expression),
4081+
\code{regsub.splitx()} (like \code{regsub.split()} but returns the
4082+
delimiters as well as the words in the resulting list). The optional
4083+
\code{maxsep} argument is also supported by \code{regsub.split()}.
40274084

40284085
\item
4029-
Module files pdb.py and profile.py can now be invoked as scripts to
4030-
debug c.q. profile other scripts easily.
4086+
Module files \code{pdb.py} and \code{profile.py} can now be invoked as
4087+
scripts to debug c.q. profile other scripts easily.
40314088

40324089
\item
40334090
The \code{os} module now supports the \code{putenv()} function on
@@ -4050,7 +4107,8 @@ \chapter{New in Release 1.4}
40504107
and ftruncate. More functions are also available under NT. XXX
40514108

40524109
\item
4053-
New function in the fcntl module: flock. XXX
4110+
New functions in the fcntl module: \code{lockf()} and \code{flock()}
4111+
(don't ask \code{:-)}). See the Library Reference Manual.
40544112

40554113
\item
40564114
The first item of the module search path, \code{sys.path}, is the
@@ -4106,7 +4164,7 @@ \chapter{New in Release 1.4}
41064164
\code{sys.exec_prefix} mentioned above.
41074165

41084166
\item
4109-
XXX
4167+
There's more. As I said, see \code{Misc/NEWS}...
41104168

41114169
\end{itemize}
41124170

0 commit comments

Comments
 (0)