mirror of
https://github.com/python/cpython.git
synced 2024-11-27 20:04:41 +08:00
Merge alpha100 branch back to main trunk
This commit is contained in:
parent
ab3a2504b9
commit
6938f06047
@ -1 +1,2 @@
|
||||
python-lib.info*
|
||||
lib.texi
|
||||
|
46
Doc/Makefile
46
Doc/Makefile
@ -2,13 +2,14 @@ DESTDIR=/usr/local
|
||||
LIBDESTDIR=$DESTDIR/lib
|
||||
LIBDEST=$LIBDESTDIR/python
|
||||
DOCDESTDIR=$LIBDEST/doc
|
||||
DVIPS= dvips -f
|
||||
|
||||
all: tut lib ref ext qua
|
||||
all: tut lib ref ext
|
||||
|
||||
tut:
|
||||
latex tut
|
||||
latex tut
|
||||
dvips tut >tut.ps
|
||||
$(DVIPS) tut >tut.ps
|
||||
|
||||
ref:
|
||||
touch ref.ind
|
||||
@ -16,7 +17,7 @@ ref:
|
||||
./fix_hack ref.idx
|
||||
makeindex ref
|
||||
latex ref
|
||||
dvips ref >ref.ps
|
||||
$(DVIPS) ref >ref.ps
|
||||
|
||||
lib:
|
||||
touch lib.ind
|
||||
@ -24,7 +25,7 @@ lib:
|
||||
./fix_hack lib.idx
|
||||
makeindex lib
|
||||
latex lib
|
||||
dvips lib >lib.ps
|
||||
$(DVIPS) lib >lib.ps
|
||||
|
||||
ext:
|
||||
touch ext.ind
|
||||
@ -32,32 +33,51 @@ ext:
|
||||
./fix_hack ext.idx
|
||||
makeindex ext
|
||||
latex ext
|
||||
dvips ext >ext.ps
|
||||
$(DVIPS) ext >ext.ps
|
||||
|
||||
qua:
|
||||
latex qua
|
||||
bibtex qua
|
||||
latex qua
|
||||
latex qua
|
||||
dvips qua >qua.ps
|
||||
$(DVIPS) qua >qua.ps
|
||||
|
||||
lib.texi: lib1.tex lib2.tex lib3.tex lib4.tex lib5.tex \
|
||||
texipre.dat texipost.dat partparse.py
|
||||
python partparse.py -o @lib.texi lib[1-5].tex
|
||||
lib.texi: lib*.tex texipre.dat texipost.dat partparse.py fix.el
|
||||
python partparse.py -o @lib.texi `whichlibs`
|
||||
emacs -batch -l fix.el -f save-buffer -kill
|
||||
mv @lib.texi lib.texi
|
||||
|
||||
.PRECIOUS: lib.texi
|
||||
|
||||
python-lib.info: lib.texi fix.el
|
||||
emacs -batch -l fix.el -f save-buffer -kill
|
||||
makeinfo +footnote-style end +fill-column 72 +paragraph-indent 0 \
|
||||
python-lib.info: lib.texi
|
||||
makeinfo --footnote-style end --fill-column 72 --paragraph-indent 0 \
|
||||
lib.texi
|
||||
|
||||
lib.info: python-lib.info
|
||||
|
||||
# This target is very local to CWI...
|
||||
libwww: lib.texi
|
||||
texi2html -d lib.texi /usr/local/ftp.cwi.nl/pub/www/texinfo/python
|
||||
texi2html -d lib.texi /ufs/guido/www/texinfo/python
|
||||
|
||||
# This one too...
|
||||
L2H= /usr/local/LaTeX2html/latex2html
|
||||
L2HARGS=-address $$USER@`domainname` -dont_include myformat -nolatex
|
||||
l2h: l2htut l2href l2hext
|
||||
|
||||
l2htut: tut
|
||||
$(L2H) $(L2HARGS) tut.tex
|
||||
@rm -rf python-tut
|
||||
mv tut python-tut
|
||||
|
||||
l2href: ref
|
||||
$(L2H) $(L2HARGS) ref.tex
|
||||
@rm -rf python-ref
|
||||
mv ref python-ref
|
||||
|
||||
l2hext: ext
|
||||
$(L2H) $(L2HARGS) ext.tex
|
||||
@rm -rf python-ext
|
||||
mv ext python-ext
|
||||
|
||||
clean:
|
||||
rm -f @* *~ *.aux *.idx *.ilg *.ind *.log *.toc *.blg *.bbl *.pyc
|
||||
|
57
Doc/README
57
Doc/README
@ -7,12 +7,14 @@ and a published article about Python.
|
||||
The following are the LaTeX source files:
|
||||
|
||||
tut.tex The tutorial
|
||||
lib.tex, lib[1-5].tex The library reference
|
||||
lib.tex, lib*.tex The library reference
|
||||
ref.tex, ref[1-8].tex The reference manual
|
||||
ext.tex How to extend Python
|
||||
qua.tex, quabib.bib Article published in CWI Quarterly
|
||||
|
||||
All except qua.tex use the style option file "myformat.sty". This
|
||||
contains some macro definitions and sets some style parameters.
|
||||
All except qua.tex (which isn't built by the default target) use the
|
||||
style option file "myformat.sty". This contains some macro
|
||||
definitions and sets some style parameters.
|
||||
|
||||
The style parameters are set up for European paper size (21 x 29.7 cm,
|
||||
a.k.a. A4, or roughly 8.27 x 11.7 inch) by default. To use US paper,
|
||||
@ -33,8 +35,10 @@ local conventions; at my site, I use dvips and lpr. For example:
|
||||
dvips -Ppsc ref | lpr -Ppsc # print it on printer "psc".
|
||||
|
||||
If you don't have latex, you can ftp the pre-formatted PosytScript
|
||||
versions of the documents; see "../misc/FTP" for information about
|
||||
ftp-ing Python files.
|
||||
versions of the documents. It should be in the same place where you
|
||||
fetched the main Python distribution, if you got it by ftp. (See
|
||||
"../Misc/FAQ" for information about ftp-ing Python files.)
|
||||
|
||||
|
||||
Making the INFO version of the Library Reference
|
||||
------------------------------------------------
|
||||
@ -43,44 +47,35 @@ The Library Reference can now also be read in hypertext form using the
|
||||
Emacs INFO system. This uses Texinfo format as an intermediate step.
|
||||
It requires texinfo version 2 (we have used 2.14).
|
||||
|
||||
To build the info files (python-lib.info*), say "make libinfo". This
|
||||
To build the info files (python-lib.info*), say "make lib.info". This
|
||||
takes a while, even on machines with 33 MIPS and 16 Mbytes :-) You can
|
||||
ignore the output.
|
||||
|
||||
But first you'll have to change a site dependency in fix.el: if
|
||||
texinfo 2.xx is installed by default at your site, comment out the two
|
||||
lines starting with "(setq load-path"; if it isn't, change the path!
|
||||
(I'm afraid that if you don't have texinfo 2.xx this won't work -- use
|
||||
archie to locate a version and ftp to fetch it.)
|
||||
texinfo 2.xx isn't installed by default at your site, you'll have to
|
||||
install it (use archie to locate a version and ftp to fetch it). If
|
||||
you can't install it in the standard Emacs load path, uncomment the
|
||||
line containing a "(setq load-path ...)" statement, and fill in the
|
||||
path where you put it.
|
||||
|
||||
The files used by the conversion process are:
|
||||
|
||||
partparse.py the dirty-written Python script that converts
|
||||
LaTeX sources to texi files. Output is left in
|
||||
`@out.texi'
|
||||
partparse.py Python script that converts LaTeX sources to
|
||||
texi files.
|
||||
|
||||
texi{pre,post}.dat these files will be put before and after the
|
||||
result
|
||||
texi{pre,post}.dat Files placed before and after the result.
|
||||
|
||||
fix.sh calls emacs in order to update all the nodes and
|
||||
menus. After this, makeinfo will convert the
|
||||
texinfo-source to the info-file(s). Assumption:
|
||||
the texi-source is called `@out.texi'
|
||||
|
||||
fix.el the elisp-file executed by emacs. Two calls to
|
||||
fix.el Elisp file executed by Emacs. Two calls to
|
||||
'texinfo-all-menus-update are necessary in
|
||||
some cases
|
||||
some cases.
|
||||
|
||||
fix_hack executable shell script that fixes the results
|
||||
of the underscore hack. {\ptt \char'137} is
|
||||
back-translated to a simple underscore. This is
|
||||
needed for the texindex program
|
||||
fix_hack Shell script to fix the results of the
|
||||
"underscore hack". {\ptt \char'137} is
|
||||
back-translated to a simple underscore. This
|
||||
is needed for the texindex program.
|
||||
|
||||
handy.el some handy Emacs-macro's that helped converting
|
||||
``old'' documentation to a format that could be
|
||||
understood by the converter scipt (partparse.py).
|
||||
(You don't really need this, but, as the name
|
||||
says, these macros are "handy")
|
||||
whichlibs Shell script to print a list of lib*.tex files
|
||||
to be processed.
|
||||
|
||||
A Million thanks for Jan-Hein B\"uhrman for writing and debugging the
|
||||
convertor and related scripts, and for fixing the LaTeX sources and
|
||||
|
778
Doc/ext.tex
778
Doc/ext.tex
File diff suppressed because it is too large
Load Diff
778
Doc/ext/ext.tex
778
Doc/ext/ext.tex
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,5 @@
|
||||
; load the new texinfo package (2.xx) if not installed by default
|
||||
; (setq load-path
|
||||
; (cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
|
||||
(find-file "lib.texi")
|
||||
; (setq load-path (cons "/ufs/guido/lib/emacs/texinfo-2.14" load-path))
|
||||
(find-file "@lib.texi")
|
||||
(texinfo-all-menus-update t)
|
||||
(texinfo-all-menus-update t)
|
||||
|
@ -1 +1,2 @@
|
||||
#!/bin/sh
|
||||
sed -e 's/{\\ptt[ ]*\\char[ ]*'"'"'137}/_/g' <"$1" > "@$1" && mv "@$1" $1
|
||||
|
@ -14,7 +14,7 @@ the language, see the Python Tutorial. The Python Reference Manual
|
||||
gives a more formal definition of the language. (These manuals are not
|
||||
yet available in INFO or Texinfo format.)
|
||||
|
||||
Copyright (C) 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Copyright (C) 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
All Rights Reserved
|
||||
@ -43,7 +43,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@c The following two commands start the copyright page.
|
||||
@page
|
||||
@vskip 0pt plus 1filll
|
||||
Copyright @copyright{} 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Copyright @copyright{} 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
@center All Rights Reserved
|
||||
@ -77,7 +77,7 @@ the language, see the @cite{Python Tutorial}. The @cite{Python
|
||||
Reference Manual} gives a more formal definition of the language.
|
||||
(These manuals are not yet available in INFO or Texinfo format.)
|
||||
|
||||
This version corresponds roughly to Python version 1.0 (yet to be released).
|
||||
This version corresponds to Python version 1.0.2.
|
||||
|
||||
@end ifinfo
|
||||
|
||||
|
89
Doc/lib.tex
89
Doc/lib.tex
@ -1,9 +1,6 @@
|
||||
\documentstyle[twoside,11pt,myformat]{report}
|
||||
%\includeonly{lib5}
|
||||
|
||||
\title{\bf
|
||||
Python Library Reference
|
||||
}
|
||||
\title{Python Library Reference}
|
||||
|
||||
\author{
|
||||
Guido van Rossum \\
|
||||
@ -12,14 +9,13 @@
|
||||
E-mail: {\tt guido@cwi.nl}
|
||||
}
|
||||
|
||||
\date{19 November 1993 \\ Release 0.9.9.++} % XXX update before release!
|
||||
\date{14 Jul 1994 \\ Release 1.0.3} % XXX update before release!
|
||||
|
||||
\makeindex % tell \index to actually write the .idx file
|
||||
|
||||
% Tell \index to actually write the .idx file
|
||||
\makeindex
|
||||
|
||||
\begin{document}
|
||||
%\showthe\fam
|
||||
%\showthe\ttfam
|
||||
|
||||
\pagenumbering{roman}
|
||||
|
||||
\maketitle
|
||||
@ -46,12 +42,75 @@ language.
|
||||
\pagebreak
|
||||
|
||||
\pagenumbering{arabic}
|
||||
\include{lib1} % intro; built-in types, functions and exceptions
|
||||
\include{lib2} % built-in modules
|
||||
\include{lib3} % standard modules
|
||||
\include{lib4} % Most OS'es; UNIX only; Amoeba only
|
||||
\include{lib5} % STDWIN only; SGI machines only; SUNs only; AUDIO TOOLS
|
||||
|
||||
\input{lib.ind} % The index
|
||||
% Chapter title:
|
||||
|
||||
\input{libintro} % Introduction
|
||||
|
||||
\input{libobjs} % Built-in Types, Exceptions and Functions
|
||||
\input{libtypes}
|
||||
\input{libexcs}
|
||||
\input{libfuncs}
|
||||
|
||||
\input{libmods} % Built-in modules
|
||||
\input{libsys}
|
||||
\input{libbltin} % really __builtin__
|
||||
\input{libmain} % really __main__
|
||||
\input{libarray}
|
||||
\input{libmath}
|
||||
\input{libtime}
|
||||
\input{libregex}
|
||||
\input{libmarshal}
|
||||
\input{libstruct}
|
||||
|
||||
\input{libstd} % Standard Modules
|
||||
\input{libgetopt}
|
||||
\input{libos}
|
||||
\input{librand}
|
||||
\input{libregsub}
|
||||
\input{libstring}
|
||||
\input{libwhrandom}
|
||||
|
||||
\input{libunix} % UNIX ONLY
|
||||
\input{libdbm}
|
||||
\input{libfcntl}
|
||||
\input{libgrp}
|
||||
\input{libposix}
|
||||
\input{libposixfile} % XXX this uses lineii which partparse.py doesn't know
|
||||
\input{libppath} % really posixpath
|
||||
\input{libpwd}
|
||||
\input{libselect}
|
||||
\input{libsocket}
|
||||
\input{libthread}
|
||||
|
||||
\input{libmm} % MULTIMEDIA EXTENSIONS
|
||||
\input{libaudioop}
|
||||
\input{libimageop}
|
||||
\input{libjpeg}
|
||||
\input{librgbimg}
|
||||
|
||||
\input{libcrypto} % CRYPTOGRAPHIC EXTENSIONS
|
||||
\input{libmd5}
|
||||
\input{libmpz}
|
||||
\input{librotor}
|
||||
|
||||
%\input{libamoeba} % AMOEBA ONLY
|
||||
|
||||
%\input{libmac} % MACINTOSH ONLY
|
||||
|
||||
\input{libstdwin} % STDWIN ONLY
|
||||
|
||||
\input{libsgi} % SGI IRIX ONLY
|
||||
\input{libal}
|
||||
%\input{libaudio}
|
||||
\input{libfl}
|
||||
\input{libfm}
|
||||
\input{libgl}
|
||||
\input{libimgfile}
|
||||
%\input{libpanel}
|
||||
|
||||
\input{libsun} % SUNOS ONLY
|
||||
|
||||
\input{lib.ind} % Index
|
||||
|
||||
\end{document}
|
||||
|
@ -1,9 +1,6 @@
|
||||
\documentstyle[twoside,11pt,myformat]{report}
|
||||
%\includeonly{lib5}
|
||||
|
||||
\title{\bf
|
||||
Python Library Reference
|
||||
}
|
||||
\title{Python Library Reference}
|
||||
|
||||
\author{
|
||||
Guido van Rossum \\
|
||||
@ -12,14 +9,13 @@
|
||||
E-mail: {\tt guido@cwi.nl}
|
||||
}
|
||||
|
||||
\date{19 November 1993 \\ Release 0.9.9.++} % XXX update before release!
|
||||
\date{14 Jul 1994 \\ Release 1.0.3} % XXX update before release!
|
||||
|
||||
\makeindex % tell \index to actually write the .idx file
|
||||
|
||||
% Tell \index to actually write the .idx file
|
||||
\makeindex
|
||||
|
||||
\begin{document}
|
||||
%\showthe\fam
|
||||
%\showthe\ttfam
|
||||
|
||||
\pagenumbering{roman}
|
||||
|
||||
\maketitle
|
||||
@ -46,12 +42,75 @@ language.
|
||||
\pagebreak
|
||||
|
||||
\pagenumbering{arabic}
|
||||
\include{lib1} % intro; built-in types, functions and exceptions
|
||||
\include{lib2} % built-in modules
|
||||
\include{lib3} % standard modules
|
||||
\include{lib4} % Most OS'es; UNIX only; Amoeba only
|
||||
\include{lib5} % STDWIN only; SGI machines only; SUNs only; AUDIO TOOLS
|
||||
|
||||
\input{lib.ind} % The index
|
||||
% Chapter title:
|
||||
|
||||
\input{libintro} % Introduction
|
||||
|
||||
\input{libobjs} % Built-in Types, Exceptions and Functions
|
||||
\input{libtypes}
|
||||
\input{libexcs}
|
||||
\input{libfuncs}
|
||||
|
||||
\input{libmods} % Built-in modules
|
||||
\input{libsys}
|
||||
\input{libbltin} % really __builtin__
|
||||
\input{libmain} % really __main__
|
||||
\input{libarray}
|
||||
\input{libmath}
|
||||
\input{libtime}
|
||||
\input{libregex}
|
||||
\input{libmarshal}
|
||||
\input{libstruct}
|
||||
|
||||
\input{libstd} % Standard Modules
|
||||
\input{libgetopt}
|
||||
\input{libos}
|
||||
\input{librand}
|
||||
\input{libregsub}
|
||||
\input{libstring}
|
||||
\input{libwhrandom}
|
||||
|
||||
\input{libunix} % UNIX ONLY
|
||||
\input{libdbm}
|
||||
\input{libfcntl}
|
||||
\input{libgrp}
|
||||
\input{libposix}
|
||||
\input{libposixfile} % XXX this uses lineii which partparse.py doesn't know
|
||||
\input{libppath} % really posixpath
|
||||
\input{libpwd}
|
||||
\input{libselect}
|
||||
\input{libsocket}
|
||||
\input{libthread}
|
||||
|
||||
\input{libmm} % MULTIMEDIA EXTENSIONS
|
||||
\input{libaudioop}
|
||||
\input{libimageop}
|
||||
\input{libjpeg}
|
||||
\input{librgbimg}
|
||||
|
||||
\input{libcrypto} % CRYPTOGRAPHIC EXTENSIONS
|
||||
\input{libmd5}
|
||||
\input{libmpz}
|
||||
\input{librotor}
|
||||
|
||||
%\input{libamoeba} % AMOEBA ONLY
|
||||
|
||||
%\input{libmac} % MACINTOSH ONLY
|
||||
|
||||
\input{libstdwin} % STDWIN ONLY
|
||||
|
||||
\input{libsgi} % SGI IRIX ONLY
|
||||
\input{libal}
|
||||
%\input{libaudio}
|
||||
\input{libfl}
|
||||
\input{libfm}
|
||||
\input{libgl}
|
||||
\input{libimgfile}
|
||||
%\input{libpanel}
|
||||
|
||||
\input{libsun} % SUNOS ONLY
|
||||
|
||||
\input{lib.ind} % Index
|
||||
|
||||
\end{document}
|
||||
|
@ -1,6 +1,6 @@
|
||||
\documentstyle[twoside,11pt,myformat]{report}
|
||||
|
||||
\title{\bf Python Reference Manual}
|
||||
\title{Python Reference Manual}
|
||||
|
||||
\author{
|
||||
Guido van Rossum \\
|
||||
@ -9,7 +9,7 @@
|
||||
E-mail: {\tt guido@cwi.nl}
|
||||
}
|
||||
|
||||
\date{19 November 1993 \\ Release 0.9.9.++} % XXX update before release!
|
||||
\date{14 Jul 1994 \\ Release 1.0.3} % XXX update before release!
|
||||
|
||||
% Tell \index to actually write the .idx file
|
||||
\makeindex
|
||||
|
@ -1,6 +1,6 @@
|
||||
\documentstyle[twoside,11pt,myformat]{report}
|
||||
|
||||
\title{\bf Python Reference Manual}
|
||||
\title{Python Reference Manual}
|
||||
|
||||
\author{
|
||||
Guido van Rossum \\
|
||||
@ -9,7 +9,7 @@
|
||||
E-mail: {\tt guido@cwi.nl}
|
||||
}
|
||||
|
||||
\date{19 November 1993 \\ Release 0.9.9.++} % XXX update before release!
|
||||
\date{14 Jul 1994 \\ Release 1.0.3} % XXX update before release!
|
||||
|
||||
% Tell \index to actually write the .idx file
|
||||
\makeindex
|
||||
|
@ -43,22 +43,22 @@ name: lc_letter (lc_letter | "_")*
|
||||
lc_letter: "a"..."z"
|
||||
\end{verbatim}
|
||||
|
||||
The first line says that a \verb\name\ is an \verb\lc_letter\ followed by
|
||||
a sequence of zero or more \verb\lc_letter\s and underscores. An
|
||||
\verb\lc_letter\ in turn is any of the single characters `a' through `z'.
|
||||
The first line says that a \verb@name@ is an \verb@lc_letter@ followed by
|
||||
a sequence of zero or more \verb@lc_letter@s and underscores. An
|
||||
\verb@lc_letter@ in turn is any of the single characters `a' through `z'.
|
||||
(This rule is actually adhered to for the names defined in lexical and
|
||||
grammar rules in this document.)
|
||||
|
||||
Each rule begins with a name (which is the name defined by the rule)
|
||||
and a colon. A vertical bar (\verb\|\) is used to separate
|
||||
and a colon. A vertical bar (\verb@|@) is used to separate
|
||||
alternatives; it is the least binding operator in this notation. A
|
||||
star (\verb\*\) means zero or more repetitions of the preceding item;
|
||||
likewise, a plus (\verb\+\) means one or more repetitions, and a
|
||||
phrase enclosed in square brackets (\verb\[ ]\) means zero or one
|
||||
star (\verb@*@) means zero or more repetitions of the preceding item;
|
||||
likewise, a plus (\verb@+@) means one or more repetitions, and a
|
||||
phrase enclosed in square brackets (\verb@[ ]@) means zero or one
|
||||
occurrences (in other words, the enclosed phrase is optional). The
|
||||
\verb\*\ and \verb\+\ operators bind as tightly as possible;
|
||||
\verb@*@ and \verb@+@ operators bind as tightly as possible;
|
||||
parentheses are used for grouping. Literal strings are enclosed in
|
||||
double quotes. White space is only meaningful to separate tokens.
|
||||
quotes. White space is only meaningful to separate tokens.
|
||||
Rules are normally contained on a single line; rules with many
|
||||
alternatives may be formatted alternatively with each line after the
|
||||
first beginning with a vertical bar.
|
||||
@ -66,7 +66,7 @@ first beginning with a vertical bar.
|
||||
In lexical definitions (as the example above), two more conventions
|
||||
are used: Two literal characters separated by three dots mean a choice
|
||||
of any single character in the given (inclusive) range of ASCII
|
||||
characters. A phrase between angular brackets (\verb\<...>\) gives an
|
||||
characters. A phrase between angular brackets (\verb@<...>@) gives an
|
||||
informal description of the symbol defined; e.g. this could be used
|
||||
to describe the notion of `control character' if needed.
|
||||
\index{lexical definitions}
|
||||
|
@ -19,7 +19,7 @@ syntax (e.g. between statements in compound statements).
|
||||
|
||||
\subsection{Comments}
|
||||
|
||||
A comment starts with a hash character (\verb\#\) that is not part of
|
||||
A comment starts with a hash character (\verb@#@) that is not part of
|
||||
a string literal, and ends at the end of the physical line. A comment
|
||||
always signifies the end of the logical line. Comments are ignored by
|
||||
the syntax.
|
||||
@ -28,7 +28,7 @@ the syntax.
|
||||
\index{physical line}
|
||||
\index{hash character}
|
||||
|
||||
\subsection{Line joining}
|
||||
\subsection{Explicit line joining}
|
||||
|
||||
Two or more physical lines may be joined into logical lines using
|
||||
backslash characters (\verb/\/), as follows: when a physical line ends
|
||||
@ -37,15 +37,37 @@ joined with the following forming a single logical line, deleting the
|
||||
backslash and the following end-of-line character. For example:
|
||||
\index{physical line}
|
||||
\index{line joining}
|
||||
\index{line continuation}
|
||||
\index{backslash character}
|
||||
%
|
||||
\begin{verbatim}
|
||||
month_names = ['Januari', 'Februari', 'Maart', \
|
||||
'April', 'Mei', 'Juni', \
|
||||
'Juli', 'Augustus', 'September', \
|
||||
'Oktober', 'November', 'December']
|
||||
if 1900 < year < 2100 and 1 <= month <= 12 \
|
||||
and 1 <= day <= 31 and 0 <= hour < 24 \
|
||||
and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
|
||||
return 1
|
||||
\end{verbatim}
|
||||
|
||||
A line ending in a backslash cannot carry a comment; a backslash does
|
||||
not continue a comment (but it does continue a string literal, see
|
||||
below).
|
||||
|
||||
\subsection{Implicit line joining}
|
||||
|
||||
Expressions in parentheses, square brackets or curly braces can be
|
||||
split over more than one physical line without using backslashes.
|
||||
For example:
|
||||
|
||||
\begin{verbatim}
|
||||
month_names = ['Januari', 'Februari', 'Maart', # These are the
|
||||
'April', 'Mei', 'Juni', # Dutch names
|
||||
'Juli', 'Augustus', 'September', # for the months
|
||||
'Oktober', 'November', 'December'] # of the year
|
||||
\end{verbatim}
|
||||
|
||||
Implicitly continued lines can carry comments. The indentation of the
|
||||
continuation lines is not important. Blank continuation lines are
|
||||
allowed.
|
||||
|
||||
\subsection{Blank lines}
|
||||
|
||||
A logical line that contains only spaces, tabs, and possibly a
|
||||
@ -123,7 +145,7 @@ The following example shows various indentation errors:
|
||||
|
||||
(Actually, the first three errors are detected by the parser; only the
|
||||
last error is found by the lexical analyzer --- the indentation of
|
||||
\verb\return r\ does not match a level popped off the stack.)
|
||||
\verb@return r@ does not match a level popped off the stack.)
|
||||
|
||||
\section{Other tokens}
|
||||
|
||||
@ -159,26 +181,15 @@ identifiers. They must be spelled exactly as written here:
|
||||
\index{reserved word}
|
||||
|
||||
\begin{verbatim}
|
||||
and del for in print
|
||||
break elif from is raise
|
||||
class else global not return
|
||||
continue except if or try
|
||||
def finally import pass while
|
||||
access del from lambda return
|
||||
and elif global not try
|
||||
break else if or while
|
||||
class except import pass
|
||||
continue finally in print
|
||||
def for is raise
|
||||
\end{verbatim}
|
||||
|
||||
% # This Python program sorts and formats the above table
|
||||
% import string
|
||||
% l = []
|
||||
% try:
|
||||
% while 1:
|
||||
% l = l + string.split(raw_input())
|
||||
% except EOFError:
|
||||
% pass
|
||||
% l.sort()
|
||||
% for i in range((len(l)+4)/5):
|
||||
% for j in range(i, len(l), 5):
|
||||
% print string.ljust(l[j], 10),
|
||||
% print
|
||||
% When adding keywords, pipe it through keywords.py for reformatting
|
||||
|
||||
\section{Literals} \label{literals}
|
||||
|
||||
@ -192,17 +203,24 @@ String literals are described by the following lexical definitions:
|
||||
\index{string literal}
|
||||
|
||||
\begin{verbatim}
|
||||
stringliteral: "'" stringitem* "'"
|
||||
stringitem: stringchar | escapeseq
|
||||
stringchar: <any ASCII character except newline or "\" or "'">
|
||||
escapeseq: "'" <any ASCII character except newline>
|
||||
stringliteral: shortstring | longstring
|
||||
shortstring: "'" shortstringitem* "'" | '"' shortstringitem* '"'
|
||||
longstring: "'''" longstringitem* "'''" | '"""' longstringitem* '"""'
|
||||
shortstringitem: shortstringchar | escapeseq
|
||||
shortstringchar: <any ASCII character except "\" or newline or the quote>
|
||||
longstringchar: <any ASCII character except "\">
|
||||
escapeseq: "\" <any ASCII character>
|
||||
\end{verbatim}
|
||||
\index{ASCII}
|
||||
|
||||
String literals cannot span physical line boundaries. Escape
|
||||
sequences in strings are actually interpreted according to rules
|
||||
similar to those used by Standard C. The recognized escape sequences
|
||||
are:
|
||||
In ``long strings'' (strings surrounded by sets of three quotes),
|
||||
unescaped newlines and quotes are allowed (and are retained), except
|
||||
that three unescaped quotes in a row terminate the string. (A
|
||||
``quote'' is the character used to open the string, i.e. either
|
||||
\verb/'/ or \verb/"/.)
|
||||
|
||||
Escape sequences in strings are interpreted according to rules similar
|
||||
to those used by Standard C. The recognized escape sequences are:
|
||||
\index{physical line}
|
||||
\index{escape sequence}
|
||||
\index{Standard C}
|
||||
@ -211,8 +229,10 @@ are:
|
||||
\begin{center}
|
||||
\begin{tabular}{|l|l|}
|
||||
\hline
|
||||
\verb/\/{\em newline} & Ignored \\
|
||||
\verb/\\/ & Backslash (\verb/\/) \\
|
||||
\verb/\'/ & Single quote (\verb/'/) \\
|
||||
\verb/\"/ & Double quote (\verb/"/) \\
|
||||
\verb/\a/ & ASCII Bell (BEL) \\
|
||||
\verb/\b/ & ASCII Backspace (BS) \\
|
||||
%\verb/\E/ & ASCII Escape (ESC) \\
|
||||
@ -309,8 +329,8 @@ Some examples of floating point literals:
|
||||
\end{verbatim}
|
||||
|
||||
Note that numeric literals do not include a sign; a phrase like
|
||||
\verb\-1\ is actually an expression composed of the operator
|
||||
\verb\-\ and the literal \verb\1\.
|
||||
\verb@-1@ is actually an expression composed of the operator
|
||||
\verb@-@ and the literal \verb@1@.
|
||||
|
||||
\section{Operators}
|
||||
|
||||
@ -323,7 +343,7 @@ The following tokens are operators:
|
||||
< == > <= <> != >=
|
||||
\end{verbatim}
|
||||
|
||||
The comparison operators \verb\<>\ and \verb\!=\ are alternate
|
||||
The comparison operators \verb@<>@ and \verb@!=@ are alternate
|
||||
spellings of the same operator.
|
||||
|
||||
\section{Delimiters}
|
||||
|
220
Doc/ref/ref3.tex
220
Doc/ref/ref3.tex
@ -44,7 +44,7 @@ Some objects contain references to ``external'' resources such as open
|
||||
files or windows. It is understood that these resources are freed
|
||||
when the object is garbage-collected, but since garbage collection is
|
||||
not guaranteed to happen, such objects also provide an explicit way to
|
||||
release the external resource, usually a \verb\close\ method.
|
||||
release the external resource, usually a \verb@close@ method.
|
||||
Programs are strongly recommended to always explicitly close such
|
||||
objects.
|
||||
|
||||
@ -69,8 +69,8 @@ objects this is not allowed. E.g. after
|
||||
a = 1; b = 1; c = []; d = []
|
||||
\end{verbatim}
|
||||
|
||||
\verb\a\ and \verb\b\ may or may not refer to the same object with the
|
||||
value one, depending on the implementation, but \verb\c\ and \verb\d\
|
||||
\verb@a@ and \verb@b@ may or may not refer to the same object with the
|
||||
value one, depending on the implementation, but \verb@c@ and \verb@d@
|
||||
are guaranteed to refer to two different, unique, newly created empty
|
||||
lists.
|
||||
|
||||
@ -90,9 +90,9 @@ Some of the type descriptions below contain a paragraph listing
|
||||
`special attributes'. These are attributes that provide access to the
|
||||
implementation and are not intended for general use. Their definition
|
||||
may change in the future. There are also some `generic' special
|
||||
attributes, not listed with the individual objects: \verb\__methods__\
|
||||
attributes, not listed with the individual objects: \verb@__methods__@
|
||||
is a list of the method names of a built-in object, if it has any;
|
||||
\verb\__members__\ is a list of the data attribute names of a built-in
|
||||
\verb@__members__@ is a list of the data attribute names of a built-in
|
||||
object, if it has any.
|
||||
\index{attribute}
|
||||
\indexii{special}{attribute}
|
||||
@ -104,7 +104,7 @@ object, if it has any.
|
||||
|
||||
\item[None]
|
||||
This type has a single value. There is a single object with this value.
|
||||
This object is accessed through the built-in name \verb\None\.
|
||||
This object is accessed through the built-in name \verb@None@.
|
||||
It is returned from functions that don't explicitly return an object.
|
||||
\ttindex{None}
|
||||
\obindex{None@{\tt None}}
|
||||
@ -134,7 +134,7 @@ These represent numbers in the range $-2^{31}$ through $2^{31}-1$.
|
||||
(The range may be larger on machines with a larger natural word
|
||||
size, but not smaller.)
|
||||
When the result of an operation falls outside this range, the
|
||||
exception \verb\OverflowError\ is raised.
|
||||
exception \verb@OverflowError@ is raised.
|
||||
For the purpose of shift and mask operations, integers are assumed to
|
||||
have a binary, 2's complement notation using 32 or more bits, and
|
||||
hiding no bits from the user (i.e., all $2^{32}$ different bit
|
||||
@ -172,17 +172,17 @@ C implementation for the accepted range and handling of overflow.
|
||||
|
||||
\item[Sequences]
|
||||
These represent finite ordered sets indexed by natural numbers.
|
||||
The built-in function \verb\len()\ returns the number of elements
|
||||
The built-in function \verb@len()@ returns the number of elements
|
||||
of a sequence. When this number is $n$, the index set contains
|
||||
the numbers $0, 1, \ldots, n-1$. Element \verb\i\ of sequence
|
||||
\verb\a\ is selected by \verb\a[i]\.
|
||||
the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
||||
\verb@a@ is selected by \verb@a[i]@.
|
||||
\obindex{seqence}
|
||||
\bifuncindex{len}
|
||||
\index{index operation}
|
||||
\index{item selection}
|
||||
\index{subscription}
|
||||
|
||||
Sequences also support slicing: \verb\a[i:j]\ selects all elements
|
||||
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
||||
with index $k$ such that $i <= k < j$. When used as an expression,
|
||||
a slice is a sequence of the same type --- this implies that the
|
||||
index set is renumbered so that it starts at 0 again.
|
||||
@ -209,7 +209,7 @@ The following types are immutable sequences:
|
||||
The elements of a string are characters. There is no separate
|
||||
character type; a character is represented by a string of one element.
|
||||
Characters represent (at least) 8-bit bytes. The built-in
|
||||
functions \verb\chr()\ and \verb\ord()\ convert between characters
|
||||
functions \verb@chr()@ and \verb@ord()@ convert between characters
|
||||
and nonnegative integers representing the byte values.
|
||||
Bytes with the values 0-127 represent the corresponding ASCII values.
|
||||
The string data type is also used to represent arrays of bytes, e.g.
|
||||
@ -223,7 +223,7 @@ to hold data read from a file.
|
||||
|
||||
(On systems whose native character set is not ASCII, strings may use
|
||||
EBCDIC in their internal representation, provided the functions
|
||||
\verb\chr()\ and \verb\ord()\ implement a mapping between ASCII and
|
||||
\verb@chr()@ and \verb@ord()@ implement a mapping between ASCII and
|
||||
EBCDIC, and string comparison preserves the ASCII order.
|
||||
Or perhaps someone can propose a better rule?)
|
||||
\index{ASCII}
|
||||
@ -250,7 +250,7 @@ parentheses.
|
||||
\item[Mutable sequences]
|
||||
Mutable sequences can be changed after they are created. The
|
||||
subscription and slicing notations can be used as the target of
|
||||
assignment and \verb\del\ (delete) statements.
|
||||
assignment and \verb@del@ (delete) statements.
|
||||
\obindex{mutable sequece}
|
||||
\obindex{mutable}
|
||||
\indexii{assignment}{statement}
|
||||
@ -276,10 +276,10 @@ or 1.)
|
||||
|
||||
\item[Mapping types]
|
||||
These represent finite sets of objects indexed by arbitrary index sets.
|
||||
The subscript notation \verb\a[k]\ selects the element indexed
|
||||
by \verb\k\ from the mapping \verb\a\; this can be used in
|
||||
expressions and as the target of assignments or \verb\del\ statements.
|
||||
The built-in function \verb\len()\ returns the number of elements
|
||||
The subscript notation \verb@a[k]@ selects the element indexed
|
||||
by \verb@k@ from the mapping \verb@a@; this can be used in
|
||||
expressions and as the target of assignments or \verb@del@ statements.
|
||||
The built-in function \verb@len()@ returns the number of elements
|
||||
in a mapping.
|
||||
\bifuncindex{len}
|
||||
\index{subscription}
|
||||
@ -299,7 +299,7 @@ Numeric types used for keys obey the normal rules for numeric
|
||||
comparison: if two numbers compare equal (e.g. 1 and 1.0) then they
|
||||
can be used interchangeably to index the same dictionary entry.
|
||||
|
||||
Dictionaries are mutable; they are created by the \verb\{...}\
|
||||
Dictionaries are mutable; they are created by the \verb@{...}@
|
||||
notation (see section \ref{dict}).
|
||||
\obindex{dictionary}
|
||||
\obindex{mutable}
|
||||
@ -308,7 +308,7 @@ notation (see section \ref{dict}).
|
||||
|
||||
\item[Callable types]
|
||||
These are the types to which the function call (invocation) operation,
|
||||
written as \verb\function(argument, argument, ...)\, can be applied:
|
||||
written as \verb@function(argument, argument, ...)@, can be applied:
|
||||
\indexii{function}{call}
|
||||
\index{invocation}
|
||||
\indexii{function}{argument}
|
||||
@ -325,8 +325,8 @@ parameter list.
|
||||
\obindex{function}
|
||||
\obindex{user-defined function}
|
||||
|
||||
Special read-only attributes: \verb\func_code\ is the code object
|
||||
representing the compiled function body, and \verb\func_globals\ is (a
|
||||
Special read-only attributes: \verb@func_code@ is the code object
|
||||
representing the compiled function body, and \verb@func_globals@ is (a
|
||||
reference to) the dictionary that holds the function's global
|
||||
variables --- it implements the global name space of the module in
|
||||
which the function was defined.
|
||||
@ -346,14 +346,14 @@ shifted one to the right.
|
||||
\indexii{user-defined}{method}
|
||||
\index{object closure}
|
||||
|
||||
Special read-only attributes: \verb\im_self\ is the class instance
|
||||
object, \verb\im_func\ is the function object.
|
||||
Special read-only attributes: \verb@im_self@ is the class instance
|
||||
object, \verb@im_func@ is the function object.
|
||||
\ttindex{im_func}
|
||||
\ttindex{im_self}
|
||||
|
||||
\item[Built-in functions]
|
||||
A built-in function object is a wrapper around a C function. Examples
|
||||
of built-in functions are \verb\len\ and \verb\math.sin\. There
|
||||
of built-in functions are \verb@len@ and \verb@math.sin@. There
|
||||
are no special attributes. The number and type of the arguments are
|
||||
determined by the C function.
|
||||
\obindex{built-in function}
|
||||
@ -363,18 +363,20 @@ determined by the C function.
|
||||
\item[Built-in methods]
|
||||
This is really a different disguise of a built-in function, this time
|
||||
containing an object passed to the C function as an implicit extra
|
||||
argument. An example of a built-in method is \verb\list.append\ if
|
||||
\verb\list\ is a list object.
|
||||
argument. An example of a built-in method is \verb@list.append@ if
|
||||
\verb@list@ is a list object.
|
||||
\obindex{built-in method}
|
||||
\obindex{method}
|
||||
\indexii{built-in}{method}
|
||||
|
||||
\item[Classes]
|
||||
Class objects are described below. When a class object is called as a
|
||||
parameterless function, a new class instance (also described below) is
|
||||
created and returned. The class's initialization function is not
|
||||
called --- this is the responsibility of the caller. It is illegal to
|
||||
call a class object with one or more arguments.
|
||||
function, a new class instance (also described below) is created and
|
||||
returned. This implies a call to the class's \verb@__init__@ method
|
||||
if it has one. Any arguments are passed on to the \verb@__init__@
|
||||
method -- if there is \verb@__init__@ method, the class must be called
|
||||
without arguments.
|
||||
\ttindex{__init__}
|
||||
\obindex{class}
|
||||
\obindex{class instance}
|
||||
\obindex{instance}
|
||||
@ -383,10 +385,10 @@ call a class object with one or more arguments.
|
||||
\end{description}
|
||||
|
||||
\item[Modules]
|
||||
Modules are imported by the \verb\import\ statement (see section
|
||||
Modules are imported by the \verb@import@ statement (see section
|
||||
\ref{import}). A module object is a container for a module's name
|
||||
space, which is a dictionary (the same dictionary as referenced by the
|
||||
\verb\func_globals\ attribute of functions defined in the module).
|
||||
\verb@func_globals@ attribute of functions defined in the module).
|
||||
Module attribute references are translated to lookups in this
|
||||
dictionary. A module object does not contain the code object used to
|
||||
initialize the module (since it isn't needed once the initialization
|
||||
@ -396,8 +398,8 @@ is done).
|
||||
|
||||
Attribute assignment update the module's name space dictionary.
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the module's name
|
||||
space as a dictionary object; \verb\__name__\ yields the module's name
|
||||
Special read-only attributes: \verb@__dict__@ yields the module's name
|
||||
space as a dictionary object; \verb@__name__@ yields the module's name
|
||||
as a string object.
|
||||
\ttindex{__dict__}
|
||||
\ttindex{__name__}
|
||||
@ -423,12 +425,12 @@ Class attribute assignments update the class's dictionary, never the
|
||||
dictionary of a base class.
|
||||
\indexiii{class}{attribute}{assignment}
|
||||
|
||||
A class can be called as a parameterless function to yield a class
|
||||
instance (see above).
|
||||
A class can be called as a function to yield a class instance (see
|
||||
above).
|
||||
\indexii{class object}{call}
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the dictionary
|
||||
containing the class's name space; \verb\__bases__\ yields a tuple
|
||||
Special read-only attributes: \verb@__dict__@ yields the dictionary
|
||||
containing the class's name space; \verb@__bases__@ yields a tuple
|
||||
(possibly empty or a singleton) containing the base classes, in the
|
||||
order of their occurrence in the base class list.
|
||||
\ttindex{__dict__}
|
||||
@ -436,7 +438,7 @@ order of their occurrence in the base class list.
|
||||
|
||||
\item[Class instances]
|
||||
A class instance is created by calling a class object as a
|
||||
parameterless function. A class instance has a dictionary in which
|
||||
function. A class instance has a dictionary in which
|
||||
attribute references are searched. When an attribute is not found
|
||||
there, and the instance's class has an attribute by that name, and
|
||||
that class attribute is a user-defined function (and in no other
|
||||
@ -457,17 +459,17 @@ section \ref{specialnames}.
|
||||
\obindex{sequence}
|
||||
\obindex{mapping}
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the attribute
|
||||
dictionary; \verb\__class__\ yields the instance's class.
|
||||
Special read-only attributes: \verb@__dict__@ yields the attribute
|
||||
dictionary; \verb@__class__@ yields the instance's class.
|
||||
\ttindex{__dict__}
|
||||
\ttindex{__class__}
|
||||
|
||||
\item[Files]
|
||||
A file object represents an open file. (It is a wrapper around a C
|
||||
{\tt stdio} file pointer.) File objects are created by the
|
||||
\verb\open()\ built-in function, and also by \verb\posix.popen()\ and
|
||||
the \verb\makefile\ method of socket objects. \verb\sys.stdin\,
|
||||
\verb\sys.stdout\ and \verb\sys.stderr\ are file objects corresponding
|
||||
\verb@open()@ built-in function, and also by \verb@posix.popen()@ and
|
||||
the \verb@makefile@ method of socket objects. \verb@sys.stdin@,
|
||||
\verb@sys.stdout@ and \verb@sys.stderr@ are file objects corresponding
|
||||
the the interpreter's standard input, output and error streams.
|
||||
See the Python Library Reference for methods of file objects and other
|
||||
details.
|
||||
@ -500,12 +502,12 @@ was defined) which a code object contains no context. There is no way
|
||||
to execute a bare code object.
|
||||
\obindex{code}
|
||||
|
||||
Special read-only attributes: \verb\co_code\ is a string representing
|
||||
the sequence of instructions; \verb\co_consts\ is a list of literals
|
||||
used by the code; \verb\co_names\ is a list of names (strings) used by
|
||||
the code; \verb\co_filename\ is the filename from which the code was
|
||||
Special read-only attributes: \verb@co_code@ is a string representing
|
||||
the sequence of instructions; \verb@co_consts@ is a list of literals
|
||||
used by the code; \verb@co_names@ is a list of names (strings) used by
|
||||
the code; \verb@co_filename@ is the filename from which the code was
|
||||
compiled. (To find out the line numbers, you would have to decode the
|
||||
instructions; the standard library module \verb\dis\ contains an
|
||||
instructions; the standard library module \verb@dis@ contains an
|
||||
example of how to do this.)
|
||||
\ttindex{co_code}
|
||||
\ttindex{co_consts}
|
||||
@ -517,12 +519,12 @@ Frame objects represent execution frames. They may occur in traceback
|
||||
objects (see below).
|
||||
\obindex{frame}
|
||||
|
||||
Special read-only attributes: \verb\f_back\ is to the previous
|
||||
stack frame (towards the caller), or \verb\None\ if this is the bottom
|
||||
stack frame; \verb\f_code\ is the code object being executed in this
|
||||
frame; \verb\f_globals\ is the dictionary used to look up global
|
||||
variables; \verb\f_locals\ is used for local variables;
|
||||
\verb\f_lineno\ gives the line number and \verb\f_lasti\ gives the
|
||||
Special read-only attributes: \verb@f_back@ is to the previous
|
||||
stack frame (towards the caller), or \verb@None@ if this is the bottom
|
||||
stack frame; \verb@f_code@ is the code object being executed in this
|
||||
frame; \verb@f_globals@ is the dictionary used to look up global
|
||||
variables; \verb@f_locals@ is used for local variables;
|
||||
\verb@f_lineno@ gives the line number and \verb@f_lasti@ gives the
|
||||
precise instruction (this is an index into the instruction string of
|
||||
the code object).
|
||||
\ttindex{f_back}
|
||||
@ -539,11 +541,11 @@ for an exception handler unwinds the execution stack, at each unwound
|
||||
level a traceback object is inserted in front of the current
|
||||
traceback. When an exception handler is entered
|
||||
(see also section \ref{try}), the stack trace is
|
||||
made available to the program as \verb\sys.exc_traceback\. When the
|
||||
made available to the program as \verb@sys.exc_traceback@. When the
|
||||
program contains no suitable handler, the stack trace is written
|
||||
(nicely formatted) to the standard error stream; if the interpreter is
|
||||
interactive, it is also made available to the user as
|
||||
\verb\sys.last_traceback\.
|
||||
\verb@sys.last_traceback@.
|
||||
\obindex{traceback}
|
||||
\indexii{stack}{trace}
|
||||
\indexii{exception}{handler}
|
||||
@ -553,15 +555,15 @@ interactive, it is also made available to the user as
|
||||
\ttindex{sys.exc_traceback}
|
||||
\ttindex{sys.last_traceback}
|
||||
|
||||
Special read-only attributes: \verb\tb_next\ is the next level in the
|
||||
Special read-only attributes: \verb@tb_next@ is the next level in the
|
||||
stack trace (towards the frame where the exception occurred), or
|
||||
\verb\None\ if there is no next level; \verb\tb_frame\ points to the
|
||||
execution frame of the current level; \verb\tb_lineno\ gives the line
|
||||
number where the exception occurred; \verb\tb_lasti\ indicates the
|
||||
\verb@None@ if there is no next level; \verb@tb_frame@ points to the
|
||||
execution frame of the current level; \verb@tb_lineno@ gives the line
|
||||
number where the exception occurred; \verb@tb_lasti@ indicates the
|
||||
precise instruction. The line number and last instruction in the
|
||||
traceback may differ from the line number of its frame object if the
|
||||
exception occurred in a \verb\try\ statement with no matching
|
||||
\verb\except\ clause or with a \verb\finally\ clause.
|
||||
exception occurred in a \verb@try@ statement with no matching
|
||||
\verb@except@ clause or with a \verb@finally@ clause.
|
||||
\ttindex{tb_next}
|
||||
\ttindex{tb_frame}
|
||||
\ttindex{tb_lineno}
|
||||
@ -578,17 +580,19 @@ exception occurred in a \verb\try\ statement with no matching
|
||||
A class can implement certain operations that are invoked by special
|
||||
syntax (such as subscription or arithmetic operations) by defining
|
||||
methods with special names. For instance, if a class defines a
|
||||
method named \verb\__getitem__\, and \verb\x\ is an instance of this
|
||||
class, then \verb\x[i]\ is equivalent to \verb\x.__getitem__(i)\.
|
||||
(The reverse is not true --- if \verb\x\ is a list object,
|
||||
\verb\x.__getitem__(i)\ is not equivalent to \verb\x[i]\.)
|
||||
method named \verb@__getitem__@, and \verb@x@ is an instance of this
|
||||
class, then \verb@x[i]@ is equivalent to \verb@x.__getitem__(i)@.
|
||||
(The reverse is not true --- if \verb@x@ is a list object,
|
||||
\verb@x.__getitem__(i)@ is not equivalent to \verb@x[i]@.)
|
||||
|
||||
Except for \verb\__repr__\, \verb\__str__\ and \verb\__cmp__\,
|
||||
Except for \verb@__repr__@, \verb@__str__@ and \verb@__cmp__@,
|
||||
attempts to execute an
|
||||
operation raise an exception when no appropriate method is defined.
|
||||
For \verb\__repr__\ and \verb\__cmp__\, the traditional
|
||||
interpretations are used in this case.
|
||||
For \verb\__str__\, the \verb\__repr__\ method is used.
|
||||
For \verb@__repr__@, the default is to return a string describing the
|
||||
object's class and address.
|
||||
For \verb@__cmp__@, the default is to compare instances based on their
|
||||
address.
|
||||
For \verb@__str__@, the default is to use \verb@__repr__@.
|
||||
|
||||
|
||||
\subsection{Special methods for any type}
|
||||
@ -614,17 +618,17 @@ reference is deleted. Also note that it is not guaranteed that
|
||||
the interpreter exits.
|
||||
|
||||
\item[\tt __repr__(self)]
|
||||
Called by the \verb\repr()\ built-in function and by conversions
|
||||
Called by the \verb@repr()@ built-in function and by conversions
|
||||
(reverse quotes) to compute the string representation of an object.
|
||||
|
||||
\item[\tt __str__(self)]
|
||||
Called by the \verb\str()\ built-in function and by the \verb\print\
|
||||
Called by the \verb@str()@ built-in function and by the \verb@print@
|
||||
statement compute the string representation of an object.
|
||||
|
||||
\item[\tt __cmp__(self, other)]
|
||||
Called by all comparison operations. Should return -1 if
|
||||
\verb\self < other\, 0 if \verb\self == other\, +1 if
|
||||
\verb\self > other\. If no \code{__cmp__} operation is defined, class
|
||||
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
||||
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
||||
instances are compared by object identity (``address'').
|
||||
(Implementation note: due to limitations in the interpreter,
|
||||
exceptions raised by comparisons are ignored, and the objects will be
|
||||
@ -654,23 +658,23 @@ key's hash value is a constant.
|
||||
\begin{description}
|
||||
|
||||
\item[\tt __len__(self)]
|
||||
Called to implement the built-in function \verb\len()\. Should return
|
||||
the length of the object, an integer \verb\>=\ 0. Also, an object
|
||||
whose \verb\__len__()\ method returns 0 is considered to be false in a
|
||||
Called to implement the built-in function \verb@len()@. Should return
|
||||
the length of the object, an integer \verb@>=@ 0. Also, an object
|
||||
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
||||
Boolean context.
|
||||
|
||||
\item[\tt __getitem__(self, key)]
|
||||
Called to implement evaluation of \verb\self[key]\. Note that the
|
||||
Called to implement evaluation of \verb@self[key]@. Note that the
|
||||
special interpretation of negative keys (if the class wishes to
|
||||
emulate a sequence type) is up to the \verb\__getitem__\ method.
|
||||
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
||||
|
||||
\item[\tt __setitem__(self, key, value)]
|
||||
Called to implement assignment to \verb\self[key]\. Same note as for
|
||||
\verb\__getitem__\.
|
||||
Called to implement assignment to \verb@self[key]@. Same note as for
|
||||
\verb@__getitem__@.
|
||||
|
||||
\item[\tt __delitem__(self, key)]
|
||||
Called to implement deletion of \verb\self[key]\. Same note as for
|
||||
\verb\__getitem__\.
|
||||
Called to implement deletion of \verb@self[key]@. Same note as for
|
||||
\verb@__getitem__@.
|
||||
|
||||
\end{description}
|
||||
|
||||
@ -680,19 +684,19 @@ Called to implement deletion of \verb\self[key]\. Same note as for
|
||||
\begin{description}
|
||||
|
||||
\item[\tt __getslice__(self, i, j)]
|
||||
Called to implement evaluation of \verb\self[i:j]\. Note that missing
|
||||
\verb\i\ or \verb\j\ are replaced by 0 or \verb\len(self)\,
|
||||
respectively, and \verb\len(self)\ has been added (once) to originally
|
||||
negative \verb\i\ or \verb\j\ by the time this function is called
|
||||
(unlike for \verb\__getitem__\).
|
||||
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
||||
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
||||
respectively, and \verb@len(self)@ has been added (once) to originally
|
||||
negative \verb@i@ or \verb@j@ by the time this function is called
|
||||
(unlike for \verb@__getitem__@).
|
||||
|
||||
\item[\tt __setslice__(self, i, j, sequence)]
|
||||
Called to implement assignment to \verb\self[i:j]\. Same notes as for
|
||||
\verb\__getslice__\.
|
||||
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
||||
\verb@__getslice__@.
|
||||
|
||||
\item[\tt __delslice__(self, i, j)]
|
||||
Called to implement deletion of \verb\self[i:j]\. Same notes as for
|
||||
\verb\__getslice__\.
|
||||
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||
\verb@__getslice__@.
|
||||
|
||||
\end{description}
|
||||
|
||||
@ -713,20 +717,20 @@ Called to implement deletion of \verb\self[i:j]\. Same notes as for
|
||||
\item[\tt __and__(self, other)]\itemjoin
|
||||
\item[\tt __xor__(self, other)]\itemjoin
|
||||
\item[\tt __or__(self, other)]\itembreak
|
||||
Called to implement the binary arithmetic operations (\verb\+\,
|
||||
\verb\-\, \verb\*\, \verb\/\, \verb\%\, \verb\divmod()\, \verb\pow()\,
|
||||
\verb\<<\, \verb\>>\, \verb\&\, \verb\^\, \verb\|\).
|
||||
Called to implement the binary arithmetic operations (\verb@+@,
|
||||
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
||||
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
||||
|
||||
\item[\tt __neg__(self)]\itemjoin
|
||||
\item[\tt __pos__(self)]\itemjoin
|
||||
\item[\tt __abs__(self)]\itemjoin
|
||||
\item[\tt __invert__(self)]\itembreak
|
||||
Called to implement the unary arithmetic operations (\verb\-\, \verb\+\,
|
||||
\verb\abs()\ and \verb\~\).
|
||||
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
||||
\verb@abs()@ and \verb@~@).
|
||||
|
||||
\item[\tt __nonzero__(self)]
|
||||
Called to implement boolean testing; should return 0 or 1. An
|
||||
alternative name for this method is \verb\__len__\.
|
||||
alternative name for this method is \verb@__len__@.
|
||||
|
||||
\item[\tt __coerce__(self, other)]
|
||||
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
||||
@ -737,11 +741,11 @@ interpreter will also ask the other object to attempt a coercion (but
|
||||
sometimes, if the implementation of the other type cannot be changed,
|
||||
it is useful to do the conversion to the other type here).
|
||||
|
||||
Note that this method is not called to coerce the arguments to \verb\+\
|
||||
and \verb\*\, because these are also used to implement sequence
|
||||
Note that this method is not called to coerce the arguments to \verb@+@
|
||||
and \verb@*@, because these are also used to implement sequence
|
||||
concatenation and repetition, respectively. Also note that, for the
|
||||
same reason, in \verb\n*x\, where \verb\n\ is a built-in number and
|
||||
\verb\x\ is an instance, a call to \verb\x.__mul__(n)\ is made.%
|
||||
same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
|
||||
\verb@x@ is an instance, a call to \verb@x.__mul__(n)@ is made.%
|
||||
\footnote{The interpreter should really distinguish between
|
||||
user-defined classes implementing sequences, mappings or numbers, but
|
||||
currently it doesn't --- hence this strange exception.}
|
||||
@ -749,12 +753,12 @@ currently it doesn't --- hence this strange exception.}
|
||||
\item[\tt __int__(self)]\itemjoin
|
||||
\item[\tt __long__(self)]\itemjoin
|
||||
\item[\tt __float__(self)]\itembreak
|
||||
Called to implement the built-in functions \verb\int()\, \verb\long()\
|
||||
and \verb\float()\. Should return a value of the appropriate type.
|
||||
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
||||
and \verb@float()@. Should return a value of the appropriate type.
|
||||
|
||||
\item[\tt __oct__(self)]\itemjoin
|
||||
\item[\tt __hex__(self)]\itembreak
|
||||
Called to implement the built-in functions \verb\oct()\ and
|
||||
\verb\hex()\. Should return a string value.
|
||||
Called to implement the built-in functions \verb@oct()@ and
|
||||
\verb@hex()@. Should return a string value.
|
||||
|
||||
\end{description}
|
||||
|
@ -20,9 +20,9 @@ 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
|
||||
command typed interactively is a separate code block; a script file is
|
||||
a code block. The string argument passed to the built-in function
|
||||
\verb\eval\ and to the \verb\exec\ statement are code blocks.
|
||||
\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 is executed in an execution frame. An {\em execution
|
||||
@ -46,7 +46,7 @@ Name spaces are functionally equivalent to dictionaries.
|
||||
|
||||
The {\em local name space} of an execution frame determines the default
|
||||
place where names are defined and searched. The {\em global name
|
||||
space} determines the place where names listed in \verb\global\
|
||||
space} determines the place where names listed in \verb@global@
|
||||
statements are defined and searched, and where names that are not
|
||||
explicitly bound in the current code block are searched.
|
||||
\indexii{local}{name space}
|
||||
@ -55,25 +55,35 @@ explicitly bound in the current code block are searched.
|
||||
|
||||
Whether a name is local or global in a code block is determined by
|
||||
static inspection of the source text for the code block: in the
|
||||
absence of \verb\global\ statements, a name that is bound anywhere in
|
||||
absence of \verb@global@ statements, a name that is bound anywhere in
|
||||
the code block is local in the entire code block; all other names are
|
||||
considered global. The \verb\global\ statement forces global
|
||||
considered global. The \verb@global@ statement forces global
|
||||
interpretation of selected names throughout the code block. The
|
||||
following constructs bind names: formal parameters, \verb\import\
|
||||
following constructs bind names: formal parameters, \verb@import@
|
||||
statements, class and function definitions (these bind the class or
|
||||
function name), and targets that are identifiers if occurring in an
|
||||
assignment, \verb\for\ loop header, or \verb\except\ clause header.
|
||||
(A target occurring in a \verb\del\ statement does not bind a name.)
|
||||
assignment, \verb@for@ loop header, or \verb@except@ clause header.
|
||||
|
||||
A target occurring in a \verb@del@ statement is also considered bound
|
||||
for this purpose (though the actual semantics are to ``unbind'' the
|
||||
name).
|
||||
|
||||
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
|
||||
global name space of the module \verb\__builtin__\). When a name is not
|
||||
found at all, the \verb\NameError\ exception is raised.
|
||||
global name space of the module \verb@__builtin__@). When a name is not
|
||||
found at all, the \verb@NameError@ exception is raised.%
|
||||
\footnote{If the code block contains \verb@exec@ statement or the
|
||||
construct \verb@from ... import *@, the semantics of names not
|
||||
explicitly mentioned in a \verb@global@ statement change subtly: name
|
||||
lookup first searches the local name space, then the global one, then
|
||||
the built-in one.}
|
||||
|
||||
The following table lists the meaning of the local and global name
|
||||
space for various types of code blocks. The name space for a
|
||||
particular module is automatically created when the module is first
|
||||
referenced.
|
||||
referenced. Note that in almost all cases, the global name space is
|
||||
the name space of the containing module -- scopes in Python do not
|
||||
nest!
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{|l|l|l|l|}
|
||||
@ -81,15 +91,18 @@ referenced.
|
||||
Code block type & Global name space & Local name space & Notes \\
|
||||
\hline
|
||||
Module & n.s. for this module & same as global & \\
|
||||
Script & n.s. for \verb\__main__\ & same as global & \\
|
||||
Interactive command & n.s. for \verb\__main__\ & same as global & \\
|
||||
Script & n.s. for \verb@__main__@ & same as global & \\
|
||||
Interactive command & n.s. for \verb@__main__@ & same as global & \\
|
||||
Class definition & global n.s. of containing block & new n.s. & \\
|
||||
Function body & global n.s. of containing block & new n.s. & \\
|
||||
String passed to \verb\exec\ or \verb\eval\
|
||||
String passed to \verb@exec@ statement
|
||||
& global n.s. of cobtaining block
|
||||
& local n.s. of containing block & (1) \\
|
||||
String passed to \verb@eval()@
|
||||
& global n.s. of caller & local n.s. of caller & (1) \\
|
||||
File read by \verb\execfile\
|
||||
File read by \verb@execfile()@
|
||||
& global n.s. of caller & local n.s. of caller & (1) \\
|
||||
Expression read by \verb\input\
|
||||
Expression read by \verb@input@
|
||||
& global n.s. of caller & local n.s. of caller & \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
@ -101,7 +114,7 @@ Notes:
|
||||
|
||||
\item[n.s.] means {\em name space}
|
||||
|
||||
\item[(1)] The global and local name space for these functions can be
|
||||
\item[(1)] The global and local name space for these can be
|
||||
overridden with optional extra arguments.
|
||||
|
||||
\end{description}
|
||||
@ -123,8 +136,8 @@ where the error occurred.
|
||||
|
||||
The Python interpreter raises an exception when it detects an run-time
|
||||
error (such as division by zero). A Python program can also
|
||||
explicitly raise an exception with the \verb\raise\ statement.
|
||||
Exception handlers are specified with the \verb\try...except\
|
||||
explicitly raise an exception with the \verb@raise@ statement.
|
||||
Exception handlers are specified with the \verb@try...except@
|
||||
statement.
|
||||
|
||||
Python uses the ``termination'' model of error handling: an exception
|
||||
@ -139,10 +152,10 @@ execution of the program, or returns to its interactive main loop.
|
||||
Exceptions are identified by string objects. Two different string
|
||||
objects with the same value identify different exceptions.
|
||||
|
||||
When an exception is raised, an object (maybe \verb\None\) is passed
|
||||
When an exception is raised, an object (maybe \verb@None@) is passed
|
||||
as the exception's ``parameter''; this object does not affect the
|
||||
selection of an exception handler, but is passed to the selected
|
||||
exception handler as additional information.
|
||||
|
||||
See also the description of the \verb\try\ and \verb\raise\
|
||||
See also the description of the \verb@try@ and \verb@raise@
|
||||
statements.
|
||||
|
137
Doc/ref/ref5.tex
137
Doc/ref/ref5.tex
@ -12,14 +12,14 @@ may be used wherever an expression is required by enclosing it in
|
||||
parentheses. The only places where expressions are used in the syntax
|
||||
instead of conditions is in expression statements and on the
|
||||
right-hand side of assignment statements; this catches some nasty bugs
|
||||
like accidentally writing \verb\x == 1\ instead of \verb\x = 1\.
|
||||
like accidentally writing \verb@x == 1@ instead of \verb@x = 1@.
|
||||
\indexii{assignment}{statement}
|
||||
|
||||
The comma plays several roles in Python's syntax. It is usually an
|
||||
operator with a lower precedence than all others, but occasionally
|
||||
serves other purposes as well; e.g. it separates function arguments,
|
||||
is used in list and dictionary constructors, and has special semantics
|
||||
in \verb\print\ statements.
|
||||
in \verb@print@ statements.
|
||||
\index{comma}
|
||||
|
||||
When (one alternative of) a syntax rule has the form
|
||||
@ -28,8 +28,8 @@ When (one alternative of) a syntax rule has the form
|
||||
name: othername
|
||||
\end{verbatim}
|
||||
|
||||
and no semantics are given, the semantics of this form of \verb\name\
|
||||
are the same as for \verb\othername\.
|
||||
and no semantics are given, the semantics of this form of \verb@name@
|
||||
are the same as for \verb@othername@.
|
||||
\index{syntax}
|
||||
|
||||
\section{Arithmetic conversions}
|
||||
@ -38,7 +38,7 @@ are the same as for \verb\othername\.
|
||||
When a description of an arithmetic operator below uses the phrase
|
||||
``the numeric arguments are converted to a common type'',
|
||||
this both means that if either argument is not a number, a
|
||||
\verb\TypeError\ exception is raised, and that otherwise
|
||||
\verb@TypeError@ exception is raised, and that otherwise
|
||||
the following conversions are applied:
|
||||
\exindex{TypeError}
|
||||
\indexii{floating point}{number}
|
||||
@ -71,11 +71,13 @@ enclosure: parenth_form | list_display | dict_display | string_conversion
|
||||
\index{identifier}
|
||||
|
||||
An identifier occurring as an atom is a reference to a local, global
|
||||
or built-in name binding. If a name can be assigned to anywhere in a
|
||||
code block, and is not mentioned in a \verb\global\ statement in that
|
||||
code block, it refers to a local name throughout that code block.
|
||||
Otherwise, it refers to a global name if one exists, else to a
|
||||
built-in name.
|
||||
or built-in name binding. If a name is assigned to anywhere in a code
|
||||
block (even in unreachable code), and is not mentioned in a
|
||||
\verb@global@ statement in that code block, then it refers to a local
|
||||
name throughout that code block. When it is not assigned to anywhere
|
||||
in the block, or when it is assigned to but also explicitly listed in
|
||||
a \verb@global@ statement, it refers to a global name if one exists,
|
||||
else to a built-in name (and this binding may dynamically change).
|
||||
\indexii{name}{binding}
|
||||
\index{code block}
|
||||
\stindex{global}
|
||||
@ -84,7 +86,7 @@ built-in name.
|
||||
|
||||
When the name is bound to an object, evaluation of the atom yields
|
||||
that object. When a name is not bound, an attempt to evaluate it
|
||||
raises a \verb\NameError\ exception.
|
||||
raises a \verb@NameError@ exception.
|
||||
\exindex{NameError}
|
||||
|
||||
\subsection{Literals}
|
||||
@ -197,10 +199,10 @@ A string conversion evaluates the contained condition list and
|
||||
converts the resulting object into a string according to rules
|
||||
specific to its type.
|
||||
|
||||
If the object is a string, a number, \verb\None\, or a tuple, list or
|
||||
If the object is a string, a number, \verb@None@, or a tuple, list or
|
||||
dictionary containing only objects whose type is one of these, the
|
||||
resulting string is a valid Python expression which can be passed to
|
||||
the built-in function \verb\eval()\ to yield an expression with the
|
||||
the built-in function \verb@eval()@ to yield an expression with the
|
||||
same value (or an approximation, if floating point numbers are
|
||||
involved).
|
||||
|
||||
@ -234,7 +236,7 @@ attributeref: primary "." identifier
|
||||
The primary must evaluate to an object of a type that supports
|
||||
attribute references, e.g. a module or a list. This object is then
|
||||
asked to produce the attribute whose name is the identifier. If this
|
||||
attribute is not available, the exception \verb\AttributeError\ is
|
||||
attribute is not available, the exception \verb@AttributeError@ is
|
||||
raised. Otherwise, the type and value of the object produced is
|
||||
determined by the object. Multiple evaluations of the same attribute
|
||||
reference may yield different objects.
|
||||
@ -266,7 +268,7 @@ the value in the mapping that corresponds to that key.
|
||||
|
||||
If it is a sequence, the condition must evaluate to a plain integer.
|
||||
If this value is negative, the length of the sequence is added to it
|
||||
(so that, e.g. \verb\x[-1]\ selects the last item of \verb\x\.)
|
||||
(so that, e.g. \verb@x[-1]@ selects the last item of \verb@x@.)
|
||||
The resulting value must be a nonnegative integer smaller than the
|
||||
number of items in the sequence, and the subscription selects the item
|
||||
whose index is that value (counting from zero).
|
||||
@ -318,7 +320,7 @@ objects, and methods of class instances are callable). If it is a
|
||||
class, the argument list must be empty; otherwise, the arguments are
|
||||
evaluated.
|
||||
|
||||
A call always returns some value, possibly \verb\None\, unless it
|
||||
A call always returns some value, possibly \verb@None@, unless it
|
||||
raises an exception. How this value is computed depends on the type
|
||||
of the callable object. If it is:
|
||||
|
||||
@ -328,7 +330,7 @@ of the callable object. If it is:
|
||||
executed, passing it the argument list. The first thing the code
|
||||
block will do is bind the formal parameters to the arguments; this is
|
||||
described in section \ref{function}. When the code block executes a
|
||||
\verb\return\ statement, this specifies the return value of the
|
||||
\verb@return@ statement, this specifies the return value of the
|
||||
function call.
|
||||
\indexii{function}{call}
|
||||
\indexiii{user-defined}{function}{call}
|
||||
@ -371,22 +373,22 @@ All unary arithmetic (and bit-wise) operations have the same priority:
|
||||
u_expr: primary | "-" u_expr | "+" u_expr | "~" u_expr
|
||||
\end{verbatim}
|
||||
|
||||
The unary \verb\"-"\ (minus) operator yields the negation of its
|
||||
The unary \verb@"-"@ (minus) operator yields the negation of its
|
||||
numeric argument.
|
||||
\index{negation}
|
||||
\index{minus}
|
||||
|
||||
The unary \verb\"+"\ (plus) operator yields its numeric argument
|
||||
The unary \verb@"+"@ (plus) operator yields its numeric argument
|
||||
unchanged.
|
||||
\index{plus}
|
||||
|
||||
The unary \verb\"~"\ (invert) operator yields the bit-wise inversion
|
||||
The unary \verb@"~"@ (invert) operator yields the bit-wise inversion
|
||||
of its plain or long integer argument. The bit-wise inversion of
|
||||
\verb\x\ is defined as \verb\-(x+1)\.
|
||||
\verb@x@ is defined as \verb@-(x+1)@.
|
||||
\index{inversion}
|
||||
|
||||
In all three cases, if the argument does not have the proper type,
|
||||
a \verb\TypeError\ exception is raised.
|
||||
a \verb@TypeError@ exception is raised.
|
||||
\exindex{TypeError}
|
||||
|
||||
\section{Binary arithmetic operations}
|
||||
@ -404,7 +406,7 @@ m_expr: u_expr | m_expr "*" u_expr
|
||||
a_expr: m_expr | aexpr "+" m_expr | aexpr "-" m_expr
|
||||
\end{verbatim}
|
||||
|
||||
The \verb\"*"\ (multiplication) operator yields the product of its
|
||||
The \verb@"*"@ (multiplication) operator yields the product of its
|
||||
arguments. The arguments must either both be numbers, or one argument
|
||||
must be a plain integer and the other must be a sequence. In the
|
||||
former case, the numbers are converted to a common type and then
|
||||
@ -412,40 +414,40 @@ multiplied together. In the latter case, sequence repetition is
|
||||
performed; a negative repetition factor yields an empty sequence.
|
||||
\index{multiplication}
|
||||
|
||||
The \verb\"/"\ (division) operator yields the quotient of its
|
||||
The \verb@"/"@ (division) operator yields the quotient of its
|
||||
arguments. The numeric arguments are first converted to a common
|
||||
type. Plain or long integer division yields an integer of the same
|
||||
type; the result is that of mathematical division with the `floor'
|
||||
function applied to the result. Division by zero raises the
|
||||
\verb\ZeroDivisionError\ exception.
|
||||
\verb@ZeroDivisionError@ exception.
|
||||
\exindex{ZeroDivisionError}
|
||||
\index{division}
|
||||
|
||||
The \verb\"%"\ (modulo) operator yields the remainder from the
|
||||
The \verb@"%"@ (modulo) operator yields the remainder from the
|
||||
division of the first argument by the second. The numeric arguments
|
||||
are first converted to a common type. A zero right argument raises
|
||||
the \verb\ZeroDivisionError\ exception. The arguments may be floating
|
||||
point numbers, e.g. \verb\3.14 % 0.7\ equals \verb\0.34\. The modulo
|
||||
the \verb@ZeroDivisionError@ exception. The arguments may be floating
|
||||
point numbers, e.g. \verb@3.14 % 0.7@ equals \verb@0.34@. The modulo
|
||||
operator always yields a result with the same sign as its second
|
||||
operand (or zero); the absolute value of the result is strictly
|
||||
smaller than the second operand.
|
||||
\index{modulo}
|
||||
|
||||
The integer division and modulo operators are connected by the
|
||||
following identity: \verb\x == (x/y)*y + (x%y)\. Integer division and
|
||||
modulo are also connected with the built-in function \verb\divmod()\:
|
||||
\verb\divmod(x, y) == (x/y, x%y)\. These identities don't hold for
|
||||
following identity: \verb@x == (x/y)*y + (x%y)@. Integer division and
|
||||
modulo are also connected with the built-in function \verb@divmod()@:
|
||||
\verb@divmod(x, y) == (x/y, x%y)@. These identities don't hold for
|
||||
floating point numbers; there a similar identity holds where
|
||||
\verb\x/y\ is replaced by \verb\floor(x/y)\).
|
||||
\verb@x/y@ is replaced by \verb@floor(x/y)@).
|
||||
|
||||
The \verb\"+"\ (addition) operator yields the sum of its arguments.
|
||||
The \verb@"+"@ (addition) operator yields the sum of its arguments.
|
||||
The arguments must either both be numbers, or both sequences of the
|
||||
same type. In the former case, the numbers are converted to a common
|
||||
type and then added together. In the latter case, the sequences are
|
||||
concatenated.
|
||||
\index{addition}
|
||||
|
||||
The \verb\"-"\ (subtraction) operator yields the difference of its
|
||||
The \verb@"-"@ (subtraction) operator yields the difference of its
|
||||
arguments. The numeric arguments are first converted to a common
|
||||
type.
|
||||
\index{subtraction}
|
||||
@ -470,7 +472,7 @@ shift by $n$ bits is defined as multiplication with $2^n$; for plain
|
||||
integers there is no overflow check so this drops bits and flip the
|
||||
sign if the result is not less than $2^{31}$ in absolute value.
|
||||
|
||||
Negative shift counts raise a \verb\ValueError\ exception.
|
||||
Negative shift counts raise a \verb@ValueError@ exception.
|
||||
\exindex{ValueError}
|
||||
|
||||
\section{Binary bit-wise operations}
|
||||
@ -484,18 +486,18 @@ xor_expr: and_expr | xor_expr "^" and_expr
|
||||
or_expr: xor_expr | or_expr "|" xor_expr
|
||||
\end{verbatim}
|
||||
|
||||
The \verb\"&"\ operator yields the bitwise AND of its arguments, which
|
||||
The \verb@"&"@ operator yields the bitwise AND of its arguments, which
|
||||
must be plain or long integers. The arguments are converted to a
|
||||
common type.
|
||||
\indexii{bit-wise}{and}
|
||||
|
||||
The \verb\"^"\ operator yields the bitwise XOR (exclusive OR) of its
|
||||
The \verb@"^"@ operator yields the bitwise XOR (exclusive OR) of its
|
||||
arguments, which must be plain or long integers. The arguments are
|
||||
converted to a common type.
|
||||
\indexii{bit-wise}{xor}
|
||||
\indexii{exclusive}{or}
|
||||
|
||||
The \verb\"|"\ operator yields the bitwise (inclusive) OR of its
|
||||
The \verb@"|"@ operator yields the bitwise (inclusive) OR of its
|
||||
arguments, which must be plain or long integers. The arguments are
|
||||
converted to a common type.
|
||||
\indexii{bit-wise}{or}
|
||||
@ -507,7 +509,7 @@ converted to a common type.
|
||||
Contrary to C, all comparison operations in Python have the same
|
||||
priority, which is lower than that of any arithmetic, shifting or
|
||||
bitwise operation. Also contrary to C, expressions like
|
||||
\verb\a < b < c\ have the interpretation that is conventional in
|
||||
\verb@a < b < c@ have the interpretation that is conventional in
|
||||
mathematics:
|
||||
\index{C}
|
||||
|
||||
@ -519,23 +521,23 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in"
|
||||
Comparisons yield integer values: 1 for true, 0 for false.
|
||||
|
||||
Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is
|
||||
equivalent to $x < y$ \verb\and\ $y <= z$, except that $y$ is
|
||||
equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is
|
||||
evaluated only once (but in both cases $z$ is not evaluated at all
|
||||
when $x < y$ is found to be false).
|
||||
\indexii{chaining}{comparisons}
|
||||
|
||||
\catcode`\_=8
|
||||
Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to
|
||||
$e_0 op_1 e_1$ \verb\and\ $e_1 op_2 e_2$ \verb\and\ ... \verb\and\
|
||||
$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@
|
||||
$e_{n-1} op_n e_n$, except that each expression is evaluated at most once.
|
||||
|
||||
Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison
|
||||
between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal.
|
||||
\catcode`\_=12
|
||||
|
||||
The forms \verb\<>\ and \verb\!=\ are equivalent; for consistency with
|
||||
C, \verb\!=\ is preferred; where \verb\!=\ is mentioned below
|
||||
\verb\<>\ is also implied.
|
||||
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
||||
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
||||
\verb@<>@ is also implied.
|
||||
|
||||
The operators {\tt "<", ">", "==", ">=", "<="}, and {\tt "!="} compare
|
||||
the values of two objects. The objects needn't have the same type.
|
||||
@ -544,8 +546,8 @@ objects of different types {\em always} compare unequal, and are
|
||||
ordered consistently but arbitrarily.
|
||||
|
||||
(This unusual definition of comparison is done to simplify the
|
||||
definition of operations like sorting and the \verb\in\ and \verb\not
|
||||
in\ operators.)
|
||||
definition of operations like sorting and the \verb@in@ and
|
||||
\verb@not in@ operators.)
|
||||
|
||||
Comparison of objects of the same type depends on the type:
|
||||
|
||||
@ -556,7 +558,7 @@ Numbers are compared arithmetically.
|
||||
|
||||
\item
|
||||
Strings are compared lexicographically using the numeric equivalents
|
||||
(the result of the built-in function \verb\ord\) of their characters.
|
||||
(the result of the built-in function \verb@ord@) of their characters.
|
||||
|
||||
\item
|
||||
Tuples and lists are compared lexicographically using comparison of
|
||||
@ -579,11 +581,11 @@ execution of a program.
|
||||
|
||||
\end{itemize}
|
||||
|
||||
The operators \verb\in\ and \verb\not in\ test for sequence
|
||||
membership: if $y$ is a sequence, $x ~\verb\in\~ y$ is true if and
|
||||
The operators \verb@in@ and \verb@not in@ test for sequence
|
||||
membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and
|
||||
only if there exists an index $i$ such that $x = y[i]$.
|
||||
$x ~\verb\not in\~ y$ yields the inverse truth value. The exception
|
||||
\verb\TypeError\ is raised when $y$ is not a sequence, or when $y$ is
|
||||
$x ~\verb@not in@~ y$ yields the inverse truth value. The exception
|
||||
\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is
|
||||
a string and $x$ is not a string of length one.%
|
||||
\footnote{The latter restriction is sometimes a nuisance.}
|
||||
\opindex{in}
|
||||
@ -591,9 +593,9 @@ a string and $x$ is not a string of length one.%
|
||||
\indexii{membership}{test}
|
||||
\obindex{sequence}
|
||||
|
||||
The operators \verb\is\ and \verb\is not\ test for object identity:
|
||||
$x ~\verb\is\~ y$ is true if and only if $x$ and $y$ are the same
|
||||
object. $x ~\verb\is not\~ y$ yields the inverse truth value.
|
||||
The operators \verb@is@ and \verb@is not@ test for object identity:
|
||||
$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same
|
||||
object. $x ~\verb@is not@~ y$ yields the inverse truth value.
|
||||
\opindex{is}
|
||||
\opindex{is not}
|
||||
\indexii{identity}{test}
|
||||
@ -613,38 +615,39 @@ lambda_form: "lambda" [parameter_list]: condition
|
||||
|
||||
In the context of Boolean operations, and also when conditions are
|
||||
used by control flow statements, the following values are interpreted
|
||||
as false: \verb\None\, numeric zero of all types, empty sequences
|
||||
as false: \verb@None@, numeric zero of all types, empty sequences
|
||||
(strings, tuples and lists), and empty mappings (dictionaries). All
|
||||
other values are interpreted as true.
|
||||
|
||||
The operator \verb\not\ yields 1 if its argument is false, 0 otherwise.
|
||||
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
||||
\opindex{not}
|
||||
|
||||
The condition $x ~\verb\and\~ y$ first evaluates $x$; if $x$ is false,
|
||||
The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false,
|
||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
||||
value is returned.
|
||||
\opindex{and}
|
||||
|
||||
The condition $x ~\verb\or\~ y$ first evaluates $x$; if $x$ is true,
|
||||
The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true,
|
||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
||||
value is returned.
|
||||
\opindex{or}
|
||||
|
||||
(Note that \verb\and\ and \verb\or\ do not restrict the value and type
|
||||
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
||||
they return to 0 and 1, but rather return the last evaluated argument.
|
||||
This is sometimes useful, e.g. if \verb\s\ is a string that should be
|
||||
This is sometimes useful, e.g. if \verb@s@ is a string that should be
|
||||
replaced by a default value if it is empty, the expression
|
||||
\verb\s or 'foo'\ yields the desired value. Because \verb\not\ has to
|
||||
\verb@s or 'foo'@ yields the desired value. Because \verb@not@ has to
|
||||
invent a value anyway, it does not bother to return a value of the
|
||||
same type as its argument, so e.g. \verb\not 'foo'\ yields \verb\0\,
|
||||
not \verb\''\.)
|
||||
same type as its argument, so e.g. \verb@not 'foo'@ yields \verb@0@,
|
||||
not \verb@''@.)
|
||||
|
||||
Lambda forms (lambda expressions) have the same syntactic position as
|
||||
conditions. They are a shorthand to create anonymous functions; the
|
||||
expression \verb\lambda\ {\em arguments}\verb\:\ {\em condition}
|
||||
expression {\em {\tt lambda} arguments{\tt :} condition}
|
||||
yields a function object that behaves virtually identical to one
|
||||
defined with \verb\def\ {\em name}\verb\(\{\em arguments}\verb\) :
|
||||
return\ {\em condition}. See section \ref{function} for the syntax of
|
||||
defined with
|
||||
{\em {\tt def} name {\tt (}arguments{\tt ): return} condition}.
|
||||
See section \ref{function} for the syntax of
|
||||
parameter lists. Note that functions created with lambda forms cannot
|
||||
contain statements.
|
||||
\label{lambda}
|
||||
@ -686,4 +689,4 @@ tuple, but rather yields the value of that expression (condition).
|
||||
\indexii{trailing}{comma}
|
||||
|
||||
(To create an empty tuple, use an empty pair of parentheses:
|
||||
\verb\()\.)
|
||||
\verb@()@.)
|
||||
|
20
Doc/ref1.tex
20
Doc/ref1.tex
@ -43,22 +43,22 @@ name: lc_letter (lc_letter | "_")*
|
||||
lc_letter: "a"..."z"
|
||||
\end{verbatim}
|
||||
|
||||
The first line says that a \verb\name\ is an \verb\lc_letter\ followed by
|
||||
a sequence of zero or more \verb\lc_letter\s and underscores. An
|
||||
\verb\lc_letter\ in turn is any of the single characters `a' through `z'.
|
||||
The first line says that a \verb@name@ is an \verb@lc_letter@ followed by
|
||||
a sequence of zero or more \verb@lc_letter@s and underscores. An
|
||||
\verb@lc_letter@ in turn is any of the single characters `a' through `z'.
|
||||
(This rule is actually adhered to for the names defined in lexical and
|
||||
grammar rules in this document.)
|
||||
|
||||
Each rule begins with a name (which is the name defined by the rule)
|
||||
and a colon. A vertical bar (\verb\|\) is used to separate
|
||||
and a colon. A vertical bar (\verb@|@) is used to separate
|
||||
alternatives; it is the least binding operator in this notation. A
|
||||
star (\verb\*\) means zero or more repetitions of the preceding item;
|
||||
likewise, a plus (\verb\+\) means one or more repetitions, and a
|
||||
phrase enclosed in square brackets (\verb\[ ]\) means zero or one
|
||||
star (\verb@*@) means zero or more repetitions of the preceding item;
|
||||
likewise, a plus (\verb@+@) means one or more repetitions, and a
|
||||
phrase enclosed in square brackets (\verb@[ ]@) means zero or one
|
||||
occurrences (in other words, the enclosed phrase is optional). The
|
||||
\verb\*\ and \verb\+\ operators bind as tightly as possible;
|
||||
\verb@*@ and \verb@+@ operators bind as tightly as possible;
|
||||
parentheses are used for grouping. Literal strings are enclosed in
|
||||
double quotes. White space is only meaningful to separate tokens.
|
||||
quotes. White space is only meaningful to separate tokens.
|
||||
Rules are normally contained on a single line; rules with many
|
||||
alternatives may be formatted alternatively with each line after the
|
||||
first beginning with a vertical bar.
|
||||
@ -66,7 +66,7 @@ first beginning with a vertical bar.
|
||||
In lexical definitions (as the example above), two more conventions
|
||||
are used: Two literal characters separated by three dots mean a choice
|
||||
of any single character in the given (inclusive) range of ASCII
|
||||
characters. A phrase between angular brackets (\verb\<...>\) gives an
|
||||
characters. A phrase between angular brackets (\verb@<...>@) gives an
|
||||
informal description of the symbol defined; e.g. this could be used
|
||||
to describe the notion of `control character' if needed.
|
||||
\index{lexical definitions}
|
||||
|
92
Doc/ref2.tex
92
Doc/ref2.tex
@ -19,7 +19,7 @@ syntax (e.g. between statements in compound statements).
|
||||
|
||||
\subsection{Comments}
|
||||
|
||||
A comment starts with a hash character (\verb\#\) that is not part of
|
||||
A comment starts with a hash character (\verb@#@) that is not part of
|
||||
a string literal, and ends at the end of the physical line. A comment
|
||||
always signifies the end of the logical line. Comments are ignored by
|
||||
the syntax.
|
||||
@ -28,7 +28,7 @@ the syntax.
|
||||
\index{physical line}
|
||||
\index{hash character}
|
||||
|
||||
\subsection{Line joining}
|
||||
\subsection{Explicit line joining}
|
||||
|
||||
Two or more physical lines may be joined into logical lines using
|
||||
backslash characters (\verb/\/), as follows: when a physical line ends
|
||||
@ -37,15 +37,37 @@ joined with the following forming a single logical line, deleting the
|
||||
backslash and the following end-of-line character. For example:
|
||||
\index{physical line}
|
||||
\index{line joining}
|
||||
\index{line continuation}
|
||||
\index{backslash character}
|
||||
%
|
||||
\begin{verbatim}
|
||||
month_names = ['Januari', 'Februari', 'Maart', \
|
||||
'April', 'Mei', 'Juni', \
|
||||
'Juli', 'Augustus', 'September', \
|
||||
'Oktober', 'November', 'December']
|
||||
if 1900 < year < 2100 and 1 <= month <= 12 \
|
||||
and 1 <= day <= 31 and 0 <= hour < 24 \
|
||||
and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date
|
||||
return 1
|
||||
\end{verbatim}
|
||||
|
||||
A line ending in a backslash cannot carry a comment; a backslash does
|
||||
not continue a comment (but it does continue a string literal, see
|
||||
below).
|
||||
|
||||
\subsection{Implicit line joining}
|
||||
|
||||
Expressions in parentheses, square brackets or curly braces can be
|
||||
split over more than one physical line without using backslashes.
|
||||
For example:
|
||||
|
||||
\begin{verbatim}
|
||||
month_names = ['Januari', 'Februari', 'Maart', # These are the
|
||||
'April', 'Mei', 'Juni', # Dutch names
|
||||
'Juli', 'Augustus', 'September', # for the months
|
||||
'Oktober', 'November', 'December'] # of the year
|
||||
\end{verbatim}
|
||||
|
||||
Implicitly continued lines can carry comments. The indentation of the
|
||||
continuation lines is not important. Blank continuation lines are
|
||||
allowed.
|
||||
|
||||
\subsection{Blank lines}
|
||||
|
||||
A logical line that contains only spaces, tabs, and possibly a
|
||||
@ -123,7 +145,7 @@ The following example shows various indentation errors:
|
||||
|
||||
(Actually, the first three errors are detected by the parser; only the
|
||||
last error is found by the lexical analyzer --- the indentation of
|
||||
\verb\return r\ does not match a level popped off the stack.)
|
||||
\verb@return r@ does not match a level popped off the stack.)
|
||||
|
||||
\section{Other tokens}
|
||||
|
||||
@ -159,26 +181,15 @@ identifiers. They must be spelled exactly as written here:
|
||||
\index{reserved word}
|
||||
|
||||
\begin{verbatim}
|
||||
and del for in print
|
||||
break elif from is raise
|
||||
class else global not return
|
||||
continue except if or try
|
||||
def finally import pass while
|
||||
access del from lambda return
|
||||
and elif global not try
|
||||
break else if or while
|
||||
class except import pass
|
||||
continue finally in print
|
||||
def for is raise
|
||||
\end{verbatim}
|
||||
|
||||
% # This Python program sorts and formats the above table
|
||||
% import string
|
||||
% l = []
|
||||
% try:
|
||||
% while 1:
|
||||
% l = l + string.split(raw_input())
|
||||
% except EOFError:
|
||||
% pass
|
||||
% l.sort()
|
||||
% for i in range((len(l)+4)/5):
|
||||
% for j in range(i, len(l), 5):
|
||||
% print string.ljust(l[j], 10),
|
||||
% print
|
||||
% When adding keywords, pipe it through keywords.py for reformatting
|
||||
|
||||
\section{Literals} \label{literals}
|
||||
|
||||
@ -192,17 +203,24 @@ String literals are described by the following lexical definitions:
|
||||
\index{string literal}
|
||||
|
||||
\begin{verbatim}
|
||||
stringliteral: "'" stringitem* "'"
|
||||
stringitem: stringchar | escapeseq
|
||||
stringchar: <any ASCII character except newline or "\" or "'">
|
||||
escapeseq: "'" <any ASCII character except newline>
|
||||
stringliteral: shortstring | longstring
|
||||
shortstring: "'" shortstringitem* "'" | '"' shortstringitem* '"'
|
||||
longstring: "'''" longstringitem* "'''" | '"""' longstringitem* '"""'
|
||||
shortstringitem: shortstringchar | escapeseq
|
||||
shortstringchar: <any ASCII character except "\" or newline or the quote>
|
||||
longstringchar: <any ASCII character except "\">
|
||||
escapeseq: "\" <any ASCII character>
|
||||
\end{verbatim}
|
||||
\index{ASCII}
|
||||
|
||||
String literals cannot span physical line boundaries. Escape
|
||||
sequences in strings are actually interpreted according to rules
|
||||
similar to those used by Standard C. The recognized escape sequences
|
||||
are:
|
||||
In ``long strings'' (strings surrounded by sets of three quotes),
|
||||
unescaped newlines and quotes are allowed (and are retained), except
|
||||
that three unescaped quotes in a row terminate the string. (A
|
||||
``quote'' is the character used to open the string, i.e. either
|
||||
\verb/'/ or \verb/"/.)
|
||||
|
||||
Escape sequences in strings are interpreted according to rules similar
|
||||
to those used by Standard C. The recognized escape sequences are:
|
||||
\index{physical line}
|
||||
\index{escape sequence}
|
||||
\index{Standard C}
|
||||
@ -211,8 +229,10 @@ are:
|
||||
\begin{center}
|
||||
\begin{tabular}{|l|l|}
|
||||
\hline
|
||||
\verb/\/{\em newline} & Ignored \\
|
||||
\verb/\\/ & Backslash (\verb/\/) \\
|
||||
\verb/\'/ & Single quote (\verb/'/) \\
|
||||
\verb/\"/ & Double quote (\verb/"/) \\
|
||||
\verb/\a/ & ASCII Bell (BEL) \\
|
||||
\verb/\b/ & ASCII Backspace (BS) \\
|
||||
%\verb/\E/ & ASCII Escape (ESC) \\
|
||||
@ -309,8 +329,8 @@ Some examples of floating point literals:
|
||||
\end{verbatim}
|
||||
|
||||
Note that numeric literals do not include a sign; a phrase like
|
||||
\verb\-1\ is actually an expression composed of the operator
|
||||
\verb\-\ and the literal \verb\1\.
|
||||
\verb@-1@ is actually an expression composed of the operator
|
||||
\verb@-@ and the literal \verb@1@.
|
||||
|
||||
\section{Operators}
|
||||
|
||||
@ -323,7 +343,7 @@ The following tokens are operators:
|
||||
< == > <= <> != >=
|
||||
\end{verbatim}
|
||||
|
||||
The comparison operators \verb\<>\ and \verb\!=\ are alternate
|
||||
The comparison operators \verb@<>@ and \verb@!=@ are alternate
|
||||
spellings of the same operator.
|
||||
|
||||
\section{Delimiters}
|
||||
|
220
Doc/ref3.tex
220
Doc/ref3.tex
@ -44,7 +44,7 @@ Some objects contain references to ``external'' resources such as open
|
||||
files or windows. It is understood that these resources are freed
|
||||
when the object is garbage-collected, but since garbage collection is
|
||||
not guaranteed to happen, such objects also provide an explicit way to
|
||||
release the external resource, usually a \verb\close\ method.
|
||||
release the external resource, usually a \verb@close@ method.
|
||||
Programs are strongly recommended to always explicitly close such
|
||||
objects.
|
||||
|
||||
@ -69,8 +69,8 @@ objects this is not allowed. E.g. after
|
||||
a = 1; b = 1; c = []; d = []
|
||||
\end{verbatim}
|
||||
|
||||
\verb\a\ and \verb\b\ may or may not refer to the same object with the
|
||||
value one, depending on the implementation, but \verb\c\ and \verb\d\
|
||||
\verb@a@ and \verb@b@ may or may not refer to the same object with the
|
||||
value one, depending on the implementation, but \verb@c@ and \verb@d@
|
||||
are guaranteed to refer to two different, unique, newly created empty
|
||||
lists.
|
||||
|
||||
@ -90,9 +90,9 @@ Some of the type descriptions below contain a paragraph listing
|
||||
`special attributes'. These are attributes that provide access to the
|
||||
implementation and are not intended for general use. Their definition
|
||||
may change in the future. There are also some `generic' special
|
||||
attributes, not listed with the individual objects: \verb\__methods__\
|
||||
attributes, not listed with the individual objects: \verb@__methods__@
|
||||
is a list of the method names of a built-in object, if it has any;
|
||||
\verb\__members__\ is a list of the data attribute names of a built-in
|
||||
\verb@__members__@ is a list of the data attribute names of a built-in
|
||||
object, if it has any.
|
||||
\index{attribute}
|
||||
\indexii{special}{attribute}
|
||||
@ -104,7 +104,7 @@ object, if it has any.
|
||||
|
||||
\item[None]
|
||||
This type has a single value. There is a single object with this value.
|
||||
This object is accessed through the built-in name \verb\None\.
|
||||
This object is accessed through the built-in name \verb@None@.
|
||||
It is returned from functions that don't explicitly return an object.
|
||||
\ttindex{None}
|
||||
\obindex{None@{\tt None}}
|
||||
@ -134,7 +134,7 @@ These represent numbers in the range $-2^{31}$ through $2^{31}-1$.
|
||||
(The range may be larger on machines with a larger natural word
|
||||
size, but not smaller.)
|
||||
When the result of an operation falls outside this range, the
|
||||
exception \verb\OverflowError\ is raised.
|
||||
exception \verb@OverflowError@ is raised.
|
||||
For the purpose of shift and mask operations, integers are assumed to
|
||||
have a binary, 2's complement notation using 32 or more bits, and
|
||||
hiding no bits from the user (i.e., all $2^{32}$ different bit
|
||||
@ -172,17 +172,17 @@ C implementation for the accepted range and handling of overflow.
|
||||
|
||||
\item[Sequences]
|
||||
These represent finite ordered sets indexed by natural numbers.
|
||||
The built-in function \verb\len()\ returns the number of elements
|
||||
The built-in function \verb@len()@ returns the number of elements
|
||||
of a sequence. When this number is $n$, the index set contains
|
||||
the numbers $0, 1, \ldots, n-1$. Element \verb\i\ of sequence
|
||||
\verb\a\ is selected by \verb\a[i]\.
|
||||
the numbers $0, 1, \ldots, n-1$. Element \verb@i@ of sequence
|
||||
\verb@a@ is selected by \verb@a[i]@.
|
||||
\obindex{seqence}
|
||||
\bifuncindex{len}
|
||||
\index{index operation}
|
||||
\index{item selection}
|
||||
\index{subscription}
|
||||
|
||||
Sequences also support slicing: \verb\a[i:j]\ selects all elements
|
||||
Sequences also support slicing: \verb@a[i:j]@ selects all elements
|
||||
with index $k$ such that $i <= k < j$. When used as an expression,
|
||||
a slice is a sequence of the same type --- this implies that the
|
||||
index set is renumbered so that it starts at 0 again.
|
||||
@ -209,7 +209,7 @@ The following types are immutable sequences:
|
||||
The elements of a string are characters. There is no separate
|
||||
character type; a character is represented by a string of one element.
|
||||
Characters represent (at least) 8-bit bytes. The built-in
|
||||
functions \verb\chr()\ and \verb\ord()\ convert between characters
|
||||
functions \verb@chr()@ and \verb@ord()@ convert between characters
|
||||
and nonnegative integers representing the byte values.
|
||||
Bytes with the values 0-127 represent the corresponding ASCII values.
|
||||
The string data type is also used to represent arrays of bytes, e.g.
|
||||
@ -223,7 +223,7 @@ to hold data read from a file.
|
||||
|
||||
(On systems whose native character set is not ASCII, strings may use
|
||||
EBCDIC in their internal representation, provided the functions
|
||||
\verb\chr()\ and \verb\ord()\ implement a mapping between ASCII and
|
||||
\verb@chr()@ and \verb@ord()@ implement a mapping between ASCII and
|
||||
EBCDIC, and string comparison preserves the ASCII order.
|
||||
Or perhaps someone can propose a better rule?)
|
||||
\index{ASCII}
|
||||
@ -250,7 +250,7 @@ parentheses.
|
||||
\item[Mutable sequences]
|
||||
Mutable sequences can be changed after they are created. The
|
||||
subscription and slicing notations can be used as the target of
|
||||
assignment and \verb\del\ (delete) statements.
|
||||
assignment and \verb@del@ (delete) statements.
|
||||
\obindex{mutable sequece}
|
||||
\obindex{mutable}
|
||||
\indexii{assignment}{statement}
|
||||
@ -276,10 +276,10 @@ or 1.)
|
||||
|
||||
\item[Mapping types]
|
||||
These represent finite sets of objects indexed by arbitrary index sets.
|
||||
The subscript notation \verb\a[k]\ selects the element indexed
|
||||
by \verb\k\ from the mapping \verb\a\; this can be used in
|
||||
expressions and as the target of assignments or \verb\del\ statements.
|
||||
The built-in function \verb\len()\ returns the number of elements
|
||||
The subscript notation \verb@a[k]@ selects the element indexed
|
||||
by \verb@k@ from the mapping \verb@a@; this can be used in
|
||||
expressions and as the target of assignments or \verb@del@ statements.
|
||||
The built-in function \verb@len()@ returns the number of elements
|
||||
in a mapping.
|
||||
\bifuncindex{len}
|
||||
\index{subscription}
|
||||
@ -299,7 +299,7 @@ Numeric types used for keys obey the normal rules for numeric
|
||||
comparison: if two numbers compare equal (e.g. 1 and 1.0) then they
|
||||
can be used interchangeably to index the same dictionary entry.
|
||||
|
||||
Dictionaries are mutable; they are created by the \verb\{...}\
|
||||
Dictionaries are mutable; they are created by the \verb@{...}@
|
||||
notation (see section \ref{dict}).
|
||||
\obindex{dictionary}
|
||||
\obindex{mutable}
|
||||
@ -308,7 +308,7 @@ notation (see section \ref{dict}).
|
||||
|
||||
\item[Callable types]
|
||||
These are the types to which the function call (invocation) operation,
|
||||
written as \verb\function(argument, argument, ...)\, can be applied:
|
||||
written as \verb@function(argument, argument, ...)@, can be applied:
|
||||
\indexii{function}{call}
|
||||
\index{invocation}
|
||||
\indexii{function}{argument}
|
||||
@ -325,8 +325,8 @@ parameter list.
|
||||
\obindex{function}
|
||||
\obindex{user-defined function}
|
||||
|
||||
Special read-only attributes: \verb\func_code\ is the code object
|
||||
representing the compiled function body, and \verb\func_globals\ is (a
|
||||
Special read-only attributes: \verb@func_code@ is the code object
|
||||
representing the compiled function body, and \verb@func_globals@ is (a
|
||||
reference to) the dictionary that holds the function's global
|
||||
variables --- it implements the global name space of the module in
|
||||
which the function was defined.
|
||||
@ -346,14 +346,14 @@ shifted one to the right.
|
||||
\indexii{user-defined}{method}
|
||||
\index{object closure}
|
||||
|
||||
Special read-only attributes: \verb\im_self\ is the class instance
|
||||
object, \verb\im_func\ is the function object.
|
||||
Special read-only attributes: \verb@im_self@ is the class instance
|
||||
object, \verb@im_func@ is the function object.
|
||||
\ttindex{im_func}
|
||||
\ttindex{im_self}
|
||||
|
||||
\item[Built-in functions]
|
||||
A built-in function object is a wrapper around a C function. Examples
|
||||
of built-in functions are \verb\len\ and \verb\math.sin\. There
|
||||
of built-in functions are \verb@len@ and \verb@math.sin@. There
|
||||
are no special attributes. The number and type of the arguments are
|
||||
determined by the C function.
|
||||
\obindex{built-in function}
|
||||
@ -363,18 +363,20 @@ determined by the C function.
|
||||
\item[Built-in methods]
|
||||
This is really a different disguise of a built-in function, this time
|
||||
containing an object passed to the C function as an implicit extra
|
||||
argument. An example of a built-in method is \verb\list.append\ if
|
||||
\verb\list\ is a list object.
|
||||
argument. An example of a built-in method is \verb@list.append@ if
|
||||
\verb@list@ is a list object.
|
||||
\obindex{built-in method}
|
||||
\obindex{method}
|
||||
\indexii{built-in}{method}
|
||||
|
||||
\item[Classes]
|
||||
Class objects are described below. When a class object is called as a
|
||||
parameterless function, a new class instance (also described below) is
|
||||
created and returned. The class's initialization function is not
|
||||
called --- this is the responsibility of the caller. It is illegal to
|
||||
call a class object with one or more arguments.
|
||||
function, a new class instance (also described below) is created and
|
||||
returned. This implies a call to the class's \verb@__init__@ method
|
||||
if it has one. Any arguments are passed on to the \verb@__init__@
|
||||
method -- if there is \verb@__init__@ method, the class must be called
|
||||
without arguments.
|
||||
\ttindex{__init__}
|
||||
\obindex{class}
|
||||
\obindex{class instance}
|
||||
\obindex{instance}
|
||||
@ -383,10 +385,10 @@ call a class object with one or more arguments.
|
||||
\end{description}
|
||||
|
||||
\item[Modules]
|
||||
Modules are imported by the \verb\import\ statement (see section
|
||||
Modules are imported by the \verb@import@ statement (see section
|
||||
\ref{import}). A module object is a container for a module's name
|
||||
space, which is a dictionary (the same dictionary as referenced by the
|
||||
\verb\func_globals\ attribute of functions defined in the module).
|
||||
\verb@func_globals@ attribute of functions defined in the module).
|
||||
Module attribute references are translated to lookups in this
|
||||
dictionary. A module object does not contain the code object used to
|
||||
initialize the module (since it isn't needed once the initialization
|
||||
@ -396,8 +398,8 @@ is done).
|
||||
|
||||
Attribute assignment update the module's name space dictionary.
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the module's name
|
||||
space as a dictionary object; \verb\__name__\ yields the module's name
|
||||
Special read-only attributes: \verb@__dict__@ yields the module's name
|
||||
space as a dictionary object; \verb@__name__@ yields the module's name
|
||||
as a string object.
|
||||
\ttindex{__dict__}
|
||||
\ttindex{__name__}
|
||||
@ -423,12 +425,12 @@ Class attribute assignments update the class's dictionary, never the
|
||||
dictionary of a base class.
|
||||
\indexiii{class}{attribute}{assignment}
|
||||
|
||||
A class can be called as a parameterless function to yield a class
|
||||
instance (see above).
|
||||
A class can be called as a function to yield a class instance (see
|
||||
above).
|
||||
\indexii{class object}{call}
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the dictionary
|
||||
containing the class's name space; \verb\__bases__\ yields a tuple
|
||||
Special read-only attributes: \verb@__dict__@ yields the dictionary
|
||||
containing the class's name space; \verb@__bases__@ yields a tuple
|
||||
(possibly empty or a singleton) containing the base classes, in the
|
||||
order of their occurrence in the base class list.
|
||||
\ttindex{__dict__}
|
||||
@ -436,7 +438,7 @@ order of their occurrence in the base class list.
|
||||
|
||||
\item[Class instances]
|
||||
A class instance is created by calling a class object as a
|
||||
parameterless function. A class instance has a dictionary in which
|
||||
function. A class instance has a dictionary in which
|
||||
attribute references are searched. When an attribute is not found
|
||||
there, and the instance's class has an attribute by that name, and
|
||||
that class attribute is a user-defined function (and in no other
|
||||
@ -457,17 +459,17 @@ section \ref{specialnames}.
|
||||
\obindex{sequence}
|
||||
\obindex{mapping}
|
||||
|
||||
Special read-only attributes: \verb\__dict__\ yields the attribute
|
||||
dictionary; \verb\__class__\ yields the instance's class.
|
||||
Special read-only attributes: \verb@__dict__@ yields the attribute
|
||||
dictionary; \verb@__class__@ yields the instance's class.
|
||||
\ttindex{__dict__}
|
||||
\ttindex{__class__}
|
||||
|
||||
\item[Files]
|
||||
A file object represents an open file. (It is a wrapper around a C
|
||||
{\tt stdio} file pointer.) File objects are created by the
|
||||
\verb\open()\ built-in function, and also by \verb\posix.popen()\ and
|
||||
the \verb\makefile\ method of socket objects. \verb\sys.stdin\,
|
||||
\verb\sys.stdout\ and \verb\sys.stderr\ are file objects corresponding
|
||||
\verb@open()@ built-in function, and also by \verb@posix.popen()@ and
|
||||
the \verb@makefile@ method of socket objects. \verb@sys.stdin@,
|
||||
\verb@sys.stdout@ and \verb@sys.stderr@ are file objects corresponding
|
||||
the the interpreter's standard input, output and error streams.
|
||||
See the Python Library Reference for methods of file objects and other
|
||||
details.
|
||||
@ -500,12 +502,12 @@ was defined) which a code object contains no context. There is no way
|
||||
to execute a bare code object.
|
||||
\obindex{code}
|
||||
|
||||
Special read-only attributes: \verb\co_code\ is a string representing
|
||||
the sequence of instructions; \verb\co_consts\ is a list of literals
|
||||
used by the code; \verb\co_names\ is a list of names (strings) used by
|
||||
the code; \verb\co_filename\ is the filename from which the code was
|
||||
Special read-only attributes: \verb@co_code@ is a string representing
|
||||
the sequence of instructions; \verb@co_consts@ is a list of literals
|
||||
used by the code; \verb@co_names@ is a list of names (strings) used by
|
||||
the code; \verb@co_filename@ is the filename from which the code was
|
||||
compiled. (To find out the line numbers, you would have to decode the
|
||||
instructions; the standard library module \verb\dis\ contains an
|
||||
instructions; the standard library module \verb@dis@ contains an
|
||||
example of how to do this.)
|
||||
\ttindex{co_code}
|
||||
\ttindex{co_consts}
|
||||
@ -517,12 +519,12 @@ Frame objects represent execution frames. They may occur in traceback
|
||||
objects (see below).
|
||||
\obindex{frame}
|
||||
|
||||
Special read-only attributes: \verb\f_back\ is to the previous
|
||||
stack frame (towards the caller), or \verb\None\ if this is the bottom
|
||||
stack frame; \verb\f_code\ is the code object being executed in this
|
||||
frame; \verb\f_globals\ is the dictionary used to look up global
|
||||
variables; \verb\f_locals\ is used for local variables;
|
||||
\verb\f_lineno\ gives the line number and \verb\f_lasti\ gives the
|
||||
Special read-only attributes: \verb@f_back@ is to the previous
|
||||
stack frame (towards the caller), or \verb@None@ if this is the bottom
|
||||
stack frame; \verb@f_code@ is the code object being executed in this
|
||||
frame; \verb@f_globals@ is the dictionary used to look up global
|
||||
variables; \verb@f_locals@ is used for local variables;
|
||||
\verb@f_lineno@ gives the line number and \verb@f_lasti@ gives the
|
||||
precise instruction (this is an index into the instruction string of
|
||||
the code object).
|
||||
\ttindex{f_back}
|
||||
@ -539,11 +541,11 @@ for an exception handler unwinds the execution stack, at each unwound
|
||||
level a traceback object is inserted in front of the current
|
||||
traceback. When an exception handler is entered
|
||||
(see also section \ref{try}), the stack trace is
|
||||
made available to the program as \verb\sys.exc_traceback\. When the
|
||||
made available to the program as \verb@sys.exc_traceback@. When the
|
||||
program contains no suitable handler, the stack trace is written
|
||||
(nicely formatted) to the standard error stream; if the interpreter is
|
||||
interactive, it is also made available to the user as
|
||||
\verb\sys.last_traceback\.
|
||||
\verb@sys.last_traceback@.
|
||||
\obindex{traceback}
|
||||
\indexii{stack}{trace}
|
||||
\indexii{exception}{handler}
|
||||
@ -553,15 +555,15 @@ interactive, it is also made available to the user as
|
||||
\ttindex{sys.exc_traceback}
|
||||
\ttindex{sys.last_traceback}
|
||||
|
||||
Special read-only attributes: \verb\tb_next\ is the next level in the
|
||||
Special read-only attributes: \verb@tb_next@ is the next level in the
|
||||
stack trace (towards the frame where the exception occurred), or
|
||||
\verb\None\ if there is no next level; \verb\tb_frame\ points to the
|
||||
execution frame of the current level; \verb\tb_lineno\ gives the line
|
||||
number where the exception occurred; \verb\tb_lasti\ indicates the
|
||||
\verb@None@ if there is no next level; \verb@tb_frame@ points to the
|
||||
execution frame of the current level; \verb@tb_lineno@ gives the line
|
||||
number where the exception occurred; \verb@tb_lasti@ indicates the
|
||||
precise instruction. The line number and last instruction in the
|
||||
traceback may differ from the line number of its frame object if the
|
||||
exception occurred in a \verb\try\ statement with no matching
|
||||
\verb\except\ clause or with a \verb\finally\ clause.
|
||||
exception occurred in a \verb@try@ statement with no matching
|
||||
\verb@except@ clause or with a \verb@finally@ clause.
|
||||
\ttindex{tb_next}
|
||||
\ttindex{tb_frame}
|
||||
\ttindex{tb_lineno}
|
||||
@ -578,17 +580,19 @@ exception occurred in a \verb\try\ statement with no matching
|
||||
A class can implement certain operations that are invoked by special
|
||||
syntax (such as subscription or arithmetic operations) by defining
|
||||
methods with special names. For instance, if a class defines a
|
||||
method named \verb\__getitem__\, and \verb\x\ is an instance of this
|
||||
class, then \verb\x[i]\ is equivalent to \verb\x.__getitem__(i)\.
|
||||
(The reverse is not true --- if \verb\x\ is a list object,
|
||||
\verb\x.__getitem__(i)\ is not equivalent to \verb\x[i]\.)
|
||||
method named \verb@__getitem__@, and \verb@x@ is an instance of this
|
||||
class, then \verb@x[i]@ is equivalent to \verb@x.__getitem__(i)@.
|
||||
(The reverse is not true --- if \verb@x@ is a list object,
|
||||
\verb@x.__getitem__(i)@ is not equivalent to \verb@x[i]@.)
|
||||
|
||||
Except for \verb\__repr__\, \verb\__str__\ and \verb\__cmp__\,
|
||||
Except for \verb@__repr__@, \verb@__str__@ and \verb@__cmp__@,
|
||||
attempts to execute an
|
||||
operation raise an exception when no appropriate method is defined.
|
||||
For \verb\__repr__\ and \verb\__cmp__\, the traditional
|
||||
interpretations are used in this case.
|
||||
For \verb\__str__\, the \verb\__repr__\ method is used.
|
||||
For \verb@__repr__@, the default is to return a string describing the
|
||||
object's class and address.
|
||||
For \verb@__cmp__@, the default is to compare instances based on their
|
||||
address.
|
||||
For \verb@__str__@, the default is to use \verb@__repr__@.
|
||||
|
||||
|
||||
\subsection{Special methods for any type}
|
||||
@ -614,17 +618,17 @@ reference is deleted. Also note that it is not guaranteed that
|
||||
the interpreter exits.
|
||||
|
||||
\item[\tt __repr__(self)]
|
||||
Called by the \verb\repr()\ built-in function and by conversions
|
||||
Called by the \verb@repr()@ built-in function and by conversions
|
||||
(reverse quotes) to compute the string representation of an object.
|
||||
|
||||
\item[\tt __str__(self)]
|
||||
Called by the \verb\str()\ built-in function and by the \verb\print\
|
||||
Called by the \verb@str()@ built-in function and by the \verb@print@
|
||||
statement compute the string representation of an object.
|
||||
|
||||
\item[\tt __cmp__(self, other)]
|
||||
Called by all comparison operations. Should return -1 if
|
||||
\verb\self < other\, 0 if \verb\self == other\, +1 if
|
||||
\verb\self > other\. If no \code{__cmp__} operation is defined, class
|
||||
\verb@self < other@, 0 if \verb@self == other@, +1 if
|
||||
\verb@self > other@. If no \code{__cmp__} operation is defined, class
|
||||
instances are compared by object identity (``address'').
|
||||
(Implementation note: due to limitations in the interpreter,
|
||||
exceptions raised by comparisons are ignored, and the objects will be
|
||||
@ -654,23 +658,23 @@ key's hash value is a constant.
|
||||
\begin{description}
|
||||
|
||||
\item[\tt __len__(self)]
|
||||
Called to implement the built-in function \verb\len()\. Should return
|
||||
the length of the object, an integer \verb\>=\ 0. Also, an object
|
||||
whose \verb\__len__()\ method returns 0 is considered to be false in a
|
||||
Called to implement the built-in function \verb@len()@. Should return
|
||||
the length of the object, an integer \verb@>=@ 0. Also, an object
|
||||
whose \verb@__len__()@ method returns 0 is considered to be false in a
|
||||
Boolean context.
|
||||
|
||||
\item[\tt __getitem__(self, key)]
|
||||
Called to implement evaluation of \verb\self[key]\. Note that the
|
||||
Called to implement evaluation of \verb@self[key]@. Note that the
|
||||
special interpretation of negative keys (if the class wishes to
|
||||
emulate a sequence type) is up to the \verb\__getitem__\ method.
|
||||
emulate a sequence type) is up to the \verb@__getitem__@ method.
|
||||
|
||||
\item[\tt __setitem__(self, key, value)]
|
||||
Called to implement assignment to \verb\self[key]\. Same note as for
|
||||
\verb\__getitem__\.
|
||||
Called to implement assignment to \verb@self[key]@. Same note as for
|
||||
\verb@__getitem__@.
|
||||
|
||||
\item[\tt __delitem__(self, key)]
|
||||
Called to implement deletion of \verb\self[key]\. Same note as for
|
||||
\verb\__getitem__\.
|
||||
Called to implement deletion of \verb@self[key]@. Same note as for
|
||||
\verb@__getitem__@.
|
||||
|
||||
\end{description}
|
||||
|
||||
@ -680,19 +684,19 @@ Called to implement deletion of \verb\self[key]\. Same note as for
|
||||
\begin{description}
|
||||
|
||||
\item[\tt __getslice__(self, i, j)]
|
||||
Called to implement evaluation of \verb\self[i:j]\. Note that missing
|
||||
\verb\i\ or \verb\j\ are replaced by 0 or \verb\len(self)\,
|
||||
respectively, and \verb\len(self)\ has been added (once) to originally
|
||||
negative \verb\i\ or \verb\j\ by the time this function is called
|
||||
(unlike for \verb\__getitem__\).
|
||||
Called to implement evaluation of \verb@self[i:j]@. Note that missing
|
||||
\verb@i@ or \verb@j@ are replaced by 0 or \verb@len(self)@,
|
||||
respectively, and \verb@len(self)@ has been added (once) to originally
|
||||
negative \verb@i@ or \verb@j@ by the time this function is called
|
||||
(unlike for \verb@__getitem__@).
|
||||
|
||||
\item[\tt __setslice__(self, i, j, sequence)]
|
||||
Called to implement assignment to \verb\self[i:j]\. Same notes as for
|
||||
\verb\__getslice__\.
|
||||
Called to implement assignment to \verb@self[i:j]@. Same notes as for
|
||||
\verb@__getslice__@.
|
||||
|
||||
\item[\tt __delslice__(self, i, j)]
|
||||
Called to implement deletion of \verb\self[i:j]\. Same notes as for
|
||||
\verb\__getslice__\.
|
||||
Called to implement deletion of \verb@self[i:j]@. Same notes as for
|
||||
\verb@__getslice__@.
|
||||
|
||||
\end{description}
|
||||
|
||||
@ -713,20 +717,20 @@ Called to implement deletion of \verb\self[i:j]\. Same notes as for
|
||||
\item[\tt __and__(self, other)]\itemjoin
|
||||
\item[\tt __xor__(self, other)]\itemjoin
|
||||
\item[\tt __or__(self, other)]\itembreak
|
||||
Called to implement the binary arithmetic operations (\verb\+\,
|
||||
\verb\-\, \verb\*\, \verb\/\, \verb\%\, \verb\divmod()\, \verb\pow()\,
|
||||
\verb\<<\, \verb\>>\, \verb\&\, \verb\^\, \verb\|\).
|
||||
Called to implement the binary arithmetic operations (\verb@+@,
|
||||
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
|
||||
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
|
||||
|
||||
\item[\tt __neg__(self)]\itemjoin
|
||||
\item[\tt __pos__(self)]\itemjoin
|
||||
\item[\tt __abs__(self)]\itemjoin
|
||||
\item[\tt __invert__(self)]\itembreak
|
||||
Called to implement the unary arithmetic operations (\verb\-\, \verb\+\,
|
||||
\verb\abs()\ and \verb\~\).
|
||||
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
|
||||
\verb@abs()@ and \verb@~@).
|
||||
|
||||
\item[\tt __nonzero__(self)]
|
||||
Called to implement boolean testing; should return 0 or 1. An
|
||||
alternative name for this method is \verb\__len__\.
|
||||
alternative name for this method is \verb@__len__@.
|
||||
|
||||
\item[\tt __coerce__(self, other)]
|
||||
Called to implement ``mixed-mode'' numeric arithmetic. Should either
|
||||
@ -737,11 +741,11 @@ interpreter will also ask the other object to attempt a coercion (but
|
||||
sometimes, if the implementation of the other type cannot be changed,
|
||||
it is useful to do the conversion to the other type here).
|
||||
|
||||
Note that this method is not called to coerce the arguments to \verb\+\
|
||||
and \verb\*\, because these are also used to implement sequence
|
||||
Note that this method is not called to coerce the arguments to \verb@+@
|
||||
and \verb@*@, because these are also used to implement sequence
|
||||
concatenation and repetition, respectively. Also note that, for the
|
||||
same reason, in \verb\n*x\, where \verb\n\ is a built-in number and
|
||||
\verb\x\ is an instance, a call to \verb\x.__mul__(n)\ is made.%
|
||||
same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
|
||||
\verb@x@ is an instance, a call to \verb@x.__mul__(n)@ is made.%
|
||||
\footnote{The interpreter should really distinguish between
|
||||
user-defined classes implementing sequences, mappings or numbers, but
|
||||
currently it doesn't --- hence this strange exception.}
|
||||
@ -749,12 +753,12 @@ currently it doesn't --- hence this strange exception.}
|
||||
\item[\tt __int__(self)]\itemjoin
|
||||
\item[\tt __long__(self)]\itemjoin
|
||||
\item[\tt __float__(self)]\itembreak
|
||||
Called to implement the built-in functions \verb\int()\, \verb\long()\
|
||||
and \verb\float()\. Should return a value of the appropriate type.
|
||||
Called to implement the built-in functions \verb@int()@, \verb@long()@
|
||||
and \verb@float()@. Should return a value of the appropriate type.
|
||||
|
||||
\item[\tt __oct__(self)]\itemjoin
|
||||
\item[\tt __hex__(self)]\itembreak
|
||||
Called to implement the built-in functions \verb\oct()\ and
|
||||
\verb\hex()\. Should return a string value.
|
||||
Called to implement the built-in functions \verb@oct()@ and
|
||||
\verb@hex()@. Should return a string value.
|
||||
|
||||
\end{description}
|
||||
|
55
Doc/ref4.tex
55
Doc/ref4.tex
@ -20,9 +20,9 @@ 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
|
||||
command typed interactively is a separate code block; a script file is
|
||||
a code block. The string argument passed to the built-in function
|
||||
\verb\eval\ and to the \verb\exec\ statement are code blocks.
|
||||
\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 is executed in an execution frame. An {\em execution
|
||||
@ -46,7 +46,7 @@ Name spaces are functionally equivalent to dictionaries.
|
||||
|
||||
The {\em local name space} of an execution frame determines the default
|
||||
place where names are defined and searched. The {\em global name
|
||||
space} determines the place where names listed in \verb\global\
|
||||
space} determines the place where names listed in \verb@global@
|
||||
statements are defined and searched, and where names that are not
|
||||
explicitly bound in the current code block are searched.
|
||||
\indexii{local}{name space}
|
||||
@ -55,25 +55,35 @@ explicitly bound in the current code block are searched.
|
||||
|
||||
Whether a name is local or global in a code block is determined by
|
||||
static inspection of the source text for the code block: in the
|
||||
absence of \verb\global\ statements, a name that is bound anywhere in
|
||||
absence of \verb@global@ statements, a name that is bound anywhere in
|
||||
the code block is local in the entire code block; all other names are
|
||||
considered global. The \verb\global\ statement forces global
|
||||
considered global. The \verb@global@ statement forces global
|
||||
interpretation of selected names throughout the code block. The
|
||||
following constructs bind names: formal parameters, \verb\import\
|
||||
following constructs bind names: formal parameters, \verb@import@
|
||||
statements, class and function definitions (these bind the class or
|
||||
function name), and targets that are identifiers if occurring in an
|
||||
assignment, \verb\for\ loop header, or \verb\except\ clause header.
|
||||
(A target occurring in a \verb\del\ statement does not bind a name.)
|
||||
assignment, \verb@for@ loop header, or \verb@except@ clause header.
|
||||
|
||||
A target occurring in a \verb@del@ statement is also considered bound
|
||||
for this purpose (though the actual semantics are to ``unbind'' the
|
||||
name).
|
||||
|
||||
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
|
||||
global name space of the module \verb\__builtin__\). When a name is not
|
||||
found at all, the \verb\NameError\ exception is raised.
|
||||
global name space of the module \verb@__builtin__@). When a name is not
|
||||
found at all, the \verb@NameError@ exception is raised.%
|
||||
\footnote{If the code block contains \verb@exec@ statement or the
|
||||
construct \verb@from ... import *@, the semantics of names not
|
||||
explicitly mentioned in a \verb@global@ statement change subtly: name
|
||||
lookup first searches the local name space, then the global one, then
|
||||
the built-in one.}
|
||||
|
||||
The following table lists the meaning of the local and global name
|
||||
space for various types of code blocks. The name space for a
|
||||
particular module is automatically created when the module is first
|
||||
referenced.
|
||||
referenced. Note that in almost all cases, the global name space is
|
||||
the name space of the containing module -- scopes in Python do not
|
||||
nest!
|
||||
|
||||
\begin{center}
|
||||
\begin{tabular}{|l|l|l|l|}
|
||||
@ -81,15 +91,18 @@ referenced.
|
||||
Code block type & Global name space & Local name space & Notes \\
|
||||
\hline
|
||||
Module & n.s. for this module & same as global & \\
|
||||
Script & n.s. for \verb\__main__\ & same as global & \\
|
||||
Interactive command & n.s. for \verb\__main__\ & same as global & \\
|
||||
Script & n.s. for \verb@__main__@ & same as global & \\
|
||||
Interactive command & n.s. for \verb@__main__@ & same as global & \\
|
||||
Class definition & global n.s. of containing block & new n.s. & \\
|
||||
Function body & global n.s. of containing block & new n.s. & \\
|
||||
String passed to \verb\exec\ or \verb\eval\
|
||||
String passed to \verb@exec@ statement
|
||||
& global n.s. of cobtaining block
|
||||
& local n.s. of containing block & (1) \\
|
||||
String passed to \verb@eval()@
|
||||
& global n.s. of caller & local n.s. of caller & (1) \\
|
||||
File read by \verb\execfile\
|
||||
File read by \verb@execfile()@
|
||||
& global n.s. of caller & local n.s. of caller & (1) \\
|
||||
Expression read by \verb\input\
|
||||
Expression read by \verb@input@
|
||||
& global n.s. of caller & local n.s. of caller & \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
@ -101,7 +114,7 @@ Notes:
|
||||
|
||||
\item[n.s.] means {\em name space}
|
||||
|
||||
\item[(1)] The global and local name space for these functions can be
|
||||
\item[(1)] The global and local name space for these can be
|
||||
overridden with optional extra arguments.
|
||||
|
||||
\end{description}
|
||||
@ -123,8 +136,8 @@ where the error occurred.
|
||||
|
||||
The Python interpreter raises an exception when it detects an run-time
|
||||
error (such as division by zero). A Python program can also
|
||||
explicitly raise an exception with the \verb\raise\ statement.
|
||||
Exception handlers are specified with the \verb\try...except\
|
||||
explicitly raise an exception with the \verb@raise@ statement.
|
||||
Exception handlers are specified with the \verb@try...except@
|
||||
statement.
|
||||
|
||||
Python uses the ``termination'' model of error handling: an exception
|
||||
@ -139,10 +152,10 @@ execution of the program, or returns to its interactive main loop.
|
||||
Exceptions are identified by string objects. Two different string
|
||||
objects with the same value identify different exceptions.
|
||||
|
||||
When an exception is raised, an object (maybe \verb\None\) is passed
|
||||
When an exception is raised, an object (maybe \verb@None@) is passed
|
||||
as the exception's ``parameter''; this object does not affect the
|
||||
selection of an exception handler, but is passed to the selected
|
||||
exception handler as additional information.
|
||||
|
||||
See also the description of the \verb\try\ and \verb\raise\
|
||||
See also the description of the \verb@try@ and \verb@raise@
|
||||
statements.
|
||||
|
137
Doc/ref5.tex
137
Doc/ref5.tex
@ -12,14 +12,14 @@ may be used wherever an expression is required by enclosing it in
|
||||
parentheses. The only places where expressions are used in the syntax
|
||||
instead of conditions is in expression statements and on the
|
||||
right-hand side of assignment statements; this catches some nasty bugs
|
||||
like accidentally writing \verb\x == 1\ instead of \verb\x = 1\.
|
||||
like accidentally writing \verb@x == 1@ instead of \verb@x = 1@.
|
||||
\indexii{assignment}{statement}
|
||||
|
||||
The comma plays several roles in Python's syntax. It is usually an
|
||||
operator with a lower precedence than all others, but occasionally
|
||||
serves other purposes as well; e.g. it separates function arguments,
|
||||
is used in list and dictionary constructors, and has special semantics
|
||||
in \verb\print\ statements.
|
||||
in \verb@print@ statements.
|
||||
\index{comma}
|
||||
|
||||
When (one alternative of) a syntax rule has the form
|
||||
@ -28,8 +28,8 @@ When (one alternative of) a syntax rule has the form
|
||||
name: othername
|
||||
\end{verbatim}
|
||||
|
||||
and no semantics are given, the semantics of this form of \verb\name\
|
||||
are the same as for \verb\othername\.
|
||||
and no semantics are given, the semantics of this form of \verb@name@
|
||||
are the same as for \verb@othername@.
|
||||
\index{syntax}
|
||||
|
||||
\section{Arithmetic conversions}
|
||||
@ -38,7 +38,7 @@ are the same as for \verb\othername\.
|
||||
When a description of an arithmetic operator below uses the phrase
|
||||
``the numeric arguments are converted to a common type'',
|
||||
this both means that if either argument is not a number, a
|
||||
\verb\TypeError\ exception is raised, and that otherwise
|
||||
\verb@TypeError@ exception is raised, and that otherwise
|
||||
the following conversions are applied:
|
||||
\exindex{TypeError}
|
||||
\indexii{floating point}{number}
|
||||
@ -71,11 +71,13 @@ enclosure: parenth_form | list_display | dict_display | string_conversion
|
||||
\index{identifier}
|
||||
|
||||
An identifier occurring as an atom is a reference to a local, global
|
||||
or built-in name binding. If a name can be assigned to anywhere in a
|
||||
code block, and is not mentioned in a \verb\global\ statement in that
|
||||
code block, it refers to a local name throughout that code block.
|
||||
Otherwise, it refers to a global name if one exists, else to a
|
||||
built-in name.
|
||||
or built-in name binding. If a name is assigned to anywhere in a code
|
||||
block (even in unreachable code), and is not mentioned in a
|
||||
\verb@global@ statement in that code block, then it refers to a local
|
||||
name throughout that code block. When it is not assigned to anywhere
|
||||
in the block, or when it is assigned to but also explicitly listed in
|
||||
a \verb@global@ statement, it refers to a global name if one exists,
|
||||
else to a built-in name (and this binding may dynamically change).
|
||||
\indexii{name}{binding}
|
||||
\index{code block}
|
||||
\stindex{global}
|
||||
@ -84,7 +86,7 @@ built-in name.
|
||||
|
||||
When the name is bound to an object, evaluation of the atom yields
|
||||
that object. When a name is not bound, an attempt to evaluate it
|
||||
raises a \verb\NameError\ exception.
|
||||
raises a \verb@NameError@ exception.
|
||||
\exindex{NameError}
|
||||
|
||||
\subsection{Literals}
|
||||
@ -197,10 +199,10 @@ A string conversion evaluates the contained condition list and
|
||||
converts the resulting object into a string according to rules
|
||||
specific to its type.
|
||||
|
||||
If the object is a string, a number, \verb\None\, or a tuple, list or
|
||||
If the object is a string, a number, \verb@None@, or a tuple, list or
|
||||
dictionary containing only objects whose type is one of these, the
|
||||
resulting string is a valid Python expression which can be passed to
|
||||
the built-in function \verb\eval()\ to yield an expression with the
|
||||
the built-in function \verb@eval()@ to yield an expression with the
|
||||
same value (or an approximation, if floating point numbers are
|
||||
involved).
|
||||
|
||||
@ -234,7 +236,7 @@ attributeref: primary "." identifier
|
||||
The primary must evaluate to an object of a type that supports
|
||||
attribute references, e.g. a module or a list. This object is then
|
||||
asked to produce the attribute whose name is the identifier. If this
|
||||
attribute is not available, the exception \verb\AttributeError\ is
|
||||
attribute is not available, the exception \verb@AttributeError@ is
|
||||
raised. Otherwise, the type and value of the object produced is
|
||||
determined by the object. Multiple evaluations of the same attribute
|
||||
reference may yield different objects.
|
||||
@ -266,7 +268,7 @@ the value in the mapping that corresponds to that key.
|
||||
|
||||
If it is a sequence, the condition must evaluate to a plain integer.
|
||||
If this value is negative, the length of the sequence is added to it
|
||||
(so that, e.g. \verb\x[-1]\ selects the last item of \verb\x\.)
|
||||
(so that, e.g. \verb@x[-1]@ selects the last item of \verb@x@.)
|
||||
The resulting value must be a nonnegative integer smaller than the
|
||||
number of items in the sequence, and the subscription selects the item
|
||||
whose index is that value (counting from zero).
|
||||
@ -318,7 +320,7 @@ objects, and methods of class instances are callable). If it is a
|
||||
class, the argument list must be empty; otherwise, the arguments are
|
||||
evaluated.
|
||||
|
||||
A call always returns some value, possibly \verb\None\, unless it
|
||||
A call always returns some value, possibly \verb@None@, unless it
|
||||
raises an exception. How this value is computed depends on the type
|
||||
of the callable object. If it is:
|
||||
|
||||
@ -328,7 +330,7 @@ of the callable object. If it is:
|
||||
executed, passing it the argument list. The first thing the code
|
||||
block will do is bind the formal parameters to the arguments; this is
|
||||
described in section \ref{function}. When the code block executes a
|
||||
\verb\return\ statement, this specifies the return value of the
|
||||
\verb@return@ statement, this specifies the return value of the
|
||||
function call.
|
||||
\indexii{function}{call}
|
||||
\indexiii{user-defined}{function}{call}
|
||||
@ -371,22 +373,22 @@ All unary arithmetic (and bit-wise) operations have the same priority:
|
||||
u_expr: primary | "-" u_expr | "+" u_expr | "~" u_expr
|
||||
\end{verbatim}
|
||||
|
||||
The unary \verb\"-"\ (minus) operator yields the negation of its
|
||||
The unary \verb@"-"@ (minus) operator yields the negation of its
|
||||
numeric argument.
|
||||
\index{negation}
|
||||
\index{minus}
|
||||
|
||||
The unary \verb\"+"\ (plus) operator yields its numeric argument
|
||||
The unary \verb@"+"@ (plus) operator yields its numeric argument
|
||||
unchanged.
|
||||
\index{plus}
|
||||
|
||||
The unary \verb\"~"\ (invert) operator yields the bit-wise inversion
|
||||
The unary \verb@"~"@ (invert) operator yields the bit-wise inversion
|
||||
of its plain or long integer argument. The bit-wise inversion of
|
||||
\verb\x\ is defined as \verb\-(x+1)\.
|
||||
\verb@x@ is defined as \verb@-(x+1)@.
|
||||
\index{inversion}
|
||||
|
||||
In all three cases, if the argument does not have the proper type,
|
||||
a \verb\TypeError\ exception is raised.
|
||||
a \verb@TypeError@ exception is raised.
|
||||
\exindex{TypeError}
|
||||
|
||||
\section{Binary arithmetic operations}
|
||||
@ -404,7 +406,7 @@ m_expr: u_expr | m_expr "*" u_expr
|
||||
a_expr: m_expr | aexpr "+" m_expr | aexpr "-" m_expr
|
||||
\end{verbatim}
|
||||
|
||||
The \verb\"*"\ (multiplication) operator yields the product of its
|
||||
The \verb@"*"@ (multiplication) operator yields the product of its
|
||||
arguments. The arguments must either both be numbers, or one argument
|
||||
must be a plain integer and the other must be a sequence. In the
|
||||
former case, the numbers are converted to a common type and then
|
||||
@ -412,40 +414,40 @@ multiplied together. In the latter case, sequence repetition is
|
||||
performed; a negative repetition factor yields an empty sequence.
|
||||
\index{multiplication}
|
||||
|
||||
The \verb\"/"\ (division) operator yields the quotient of its
|
||||
The \verb@"/"@ (division) operator yields the quotient of its
|
||||
arguments. The numeric arguments are first converted to a common
|
||||
type. Plain or long integer division yields an integer of the same
|
||||
type; the result is that of mathematical division with the `floor'
|
||||
function applied to the result. Division by zero raises the
|
||||
\verb\ZeroDivisionError\ exception.
|
||||
\verb@ZeroDivisionError@ exception.
|
||||
\exindex{ZeroDivisionError}
|
||||
\index{division}
|
||||
|
||||
The \verb\"%"\ (modulo) operator yields the remainder from the
|
||||
The \verb@"%"@ (modulo) operator yields the remainder from the
|
||||
division of the first argument by the second. The numeric arguments
|
||||
are first converted to a common type. A zero right argument raises
|
||||
the \verb\ZeroDivisionError\ exception. The arguments may be floating
|
||||
point numbers, e.g. \verb\3.14 % 0.7\ equals \verb\0.34\. The modulo
|
||||
the \verb@ZeroDivisionError@ exception. The arguments may be floating
|
||||
point numbers, e.g. \verb@3.14 % 0.7@ equals \verb@0.34@. The modulo
|
||||
operator always yields a result with the same sign as its second
|
||||
operand (or zero); the absolute value of the result is strictly
|
||||
smaller than the second operand.
|
||||
\index{modulo}
|
||||
|
||||
The integer division and modulo operators are connected by the
|
||||
following identity: \verb\x == (x/y)*y + (x%y)\. Integer division and
|
||||
modulo are also connected with the built-in function \verb\divmod()\:
|
||||
\verb\divmod(x, y) == (x/y, x%y)\. These identities don't hold for
|
||||
following identity: \verb@x == (x/y)*y + (x%y)@. Integer division and
|
||||
modulo are also connected with the built-in function \verb@divmod()@:
|
||||
\verb@divmod(x, y) == (x/y, x%y)@. These identities don't hold for
|
||||
floating point numbers; there a similar identity holds where
|
||||
\verb\x/y\ is replaced by \verb\floor(x/y)\).
|
||||
\verb@x/y@ is replaced by \verb@floor(x/y)@).
|
||||
|
||||
The \verb\"+"\ (addition) operator yields the sum of its arguments.
|
||||
The \verb@"+"@ (addition) operator yields the sum of its arguments.
|
||||
The arguments must either both be numbers, or both sequences of the
|
||||
same type. In the former case, the numbers are converted to a common
|
||||
type and then added together. In the latter case, the sequences are
|
||||
concatenated.
|
||||
\index{addition}
|
||||
|
||||
The \verb\"-"\ (subtraction) operator yields the difference of its
|
||||
The \verb@"-"@ (subtraction) operator yields the difference of its
|
||||
arguments. The numeric arguments are first converted to a common
|
||||
type.
|
||||
\index{subtraction}
|
||||
@ -470,7 +472,7 @@ shift by $n$ bits is defined as multiplication with $2^n$; for plain
|
||||
integers there is no overflow check so this drops bits and flip the
|
||||
sign if the result is not less than $2^{31}$ in absolute value.
|
||||
|
||||
Negative shift counts raise a \verb\ValueError\ exception.
|
||||
Negative shift counts raise a \verb@ValueError@ exception.
|
||||
\exindex{ValueError}
|
||||
|
||||
\section{Binary bit-wise operations}
|
||||
@ -484,18 +486,18 @@ xor_expr: and_expr | xor_expr "^" and_expr
|
||||
or_expr: xor_expr | or_expr "|" xor_expr
|
||||
\end{verbatim}
|
||||
|
||||
The \verb\"&"\ operator yields the bitwise AND of its arguments, which
|
||||
The \verb@"&"@ operator yields the bitwise AND of its arguments, which
|
||||
must be plain or long integers. The arguments are converted to a
|
||||
common type.
|
||||
\indexii{bit-wise}{and}
|
||||
|
||||
The \verb\"^"\ operator yields the bitwise XOR (exclusive OR) of its
|
||||
The \verb@"^"@ operator yields the bitwise XOR (exclusive OR) of its
|
||||
arguments, which must be plain or long integers. The arguments are
|
||||
converted to a common type.
|
||||
\indexii{bit-wise}{xor}
|
||||
\indexii{exclusive}{or}
|
||||
|
||||
The \verb\"|"\ operator yields the bitwise (inclusive) OR of its
|
||||
The \verb@"|"@ operator yields the bitwise (inclusive) OR of its
|
||||
arguments, which must be plain or long integers. The arguments are
|
||||
converted to a common type.
|
||||
\indexii{bit-wise}{or}
|
||||
@ -507,7 +509,7 @@ converted to a common type.
|
||||
Contrary to C, all comparison operations in Python have the same
|
||||
priority, which is lower than that of any arithmetic, shifting or
|
||||
bitwise operation. Also contrary to C, expressions like
|
||||
\verb\a < b < c\ have the interpretation that is conventional in
|
||||
\verb@a < b < c@ have the interpretation that is conventional in
|
||||
mathematics:
|
||||
\index{C}
|
||||
|
||||
@ -519,23 +521,23 @@ comp_operator: "<"|">"|"=="|">="|"<="|"<>"|"!="|"is" ["not"]|["not"] "in"
|
||||
Comparisons yield integer values: 1 for true, 0 for false.
|
||||
|
||||
Comparisons can be chained arbitrarily, e.g. $x < y <= z$ is
|
||||
equivalent to $x < y$ \verb\and\ $y <= z$, except that $y$ is
|
||||
equivalent to $x < y$ \verb@and@ $y <= z$, except that $y$ is
|
||||
evaluated only once (but in both cases $z$ is not evaluated at all
|
||||
when $x < y$ is found to be false).
|
||||
\indexii{chaining}{comparisons}
|
||||
|
||||
\catcode`\_=8
|
||||
Formally, $e_0 op_1 e_1 op_2 e_2 ...e_{n-1} op_n e_n$ is equivalent to
|
||||
$e_0 op_1 e_1$ \verb\and\ $e_1 op_2 e_2$ \verb\and\ ... \verb\and\
|
||||
$e_0 op_1 e_1$ \verb@and@ $e_1 op_2 e_2$ \verb@and@ ... \verb@and@
|
||||
$e_{n-1} op_n e_n$, except that each expression is evaluated at most once.
|
||||
|
||||
Note that $e_0 op_1 e_1 op_2 e_2$ does not imply any kind of comparison
|
||||
between $e_0$ and $e_2$, e.g. $x < y > z$ is perfectly legal.
|
||||
\catcode`\_=12
|
||||
|
||||
The forms \verb\<>\ and \verb\!=\ are equivalent; for consistency with
|
||||
C, \verb\!=\ is preferred; where \verb\!=\ is mentioned below
|
||||
\verb\<>\ is also implied.
|
||||
The forms \verb@<>@ and \verb@!=@ are equivalent; for consistency with
|
||||
C, \verb@!=@ is preferred; where \verb@!=@ is mentioned below
|
||||
\verb@<>@ is also implied.
|
||||
|
||||
The operators {\tt "<", ">", "==", ">=", "<="}, and {\tt "!="} compare
|
||||
the values of two objects. The objects needn't have the same type.
|
||||
@ -544,8 +546,8 @@ objects of different types {\em always} compare unequal, and are
|
||||
ordered consistently but arbitrarily.
|
||||
|
||||
(This unusual definition of comparison is done to simplify the
|
||||
definition of operations like sorting and the \verb\in\ and \verb\not
|
||||
in\ operators.)
|
||||
definition of operations like sorting and the \verb@in@ and
|
||||
\verb@not in@ operators.)
|
||||
|
||||
Comparison of objects of the same type depends on the type:
|
||||
|
||||
@ -556,7 +558,7 @@ Numbers are compared arithmetically.
|
||||
|
||||
\item
|
||||
Strings are compared lexicographically using the numeric equivalents
|
||||
(the result of the built-in function \verb\ord\) of their characters.
|
||||
(the result of the built-in function \verb@ord@) of their characters.
|
||||
|
||||
\item
|
||||
Tuples and lists are compared lexicographically using comparison of
|
||||
@ -579,11 +581,11 @@ execution of a program.
|
||||
|
||||
\end{itemize}
|
||||
|
||||
The operators \verb\in\ and \verb\not in\ test for sequence
|
||||
membership: if $y$ is a sequence, $x ~\verb\in\~ y$ is true if and
|
||||
The operators \verb@in@ and \verb@not in@ test for sequence
|
||||
membership: if $y$ is a sequence, $x ~\verb@in@~ y$ is true if and
|
||||
only if there exists an index $i$ such that $x = y[i]$.
|
||||
$x ~\verb\not in\~ y$ yields the inverse truth value. The exception
|
||||
\verb\TypeError\ is raised when $y$ is not a sequence, or when $y$ is
|
||||
$x ~\verb@not in@~ y$ yields the inverse truth value. The exception
|
||||
\verb@TypeError@ is raised when $y$ is not a sequence, or when $y$ is
|
||||
a string and $x$ is not a string of length one.%
|
||||
\footnote{The latter restriction is sometimes a nuisance.}
|
||||
\opindex{in}
|
||||
@ -591,9 +593,9 @@ a string and $x$ is not a string of length one.%
|
||||
\indexii{membership}{test}
|
||||
\obindex{sequence}
|
||||
|
||||
The operators \verb\is\ and \verb\is not\ test for object identity:
|
||||
$x ~\verb\is\~ y$ is true if and only if $x$ and $y$ are the same
|
||||
object. $x ~\verb\is not\~ y$ yields the inverse truth value.
|
||||
The operators \verb@is@ and \verb@is not@ test for object identity:
|
||||
$x ~\verb@is@~ y$ is true if and only if $x$ and $y$ are the same
|
||||
object. $x ~\verb@is not@~ y$ yields the inverse truth value.
|
||||
\opindex{is}
|
||||
\opindex{is not}
|
||||
\indexii{identity}{test}
|
||||
@ -613,38 +615,39 @@ lambda_form: "lambda" [parameter_list]: condition
|
||||
|
||||
In the context of Boolean operations, and also when conditions are
|
||||
used by control flow statements, the following values are interpreted
|
||||
as false: \verb\None\, numeric zero of all types, empty sequences
|
||||
as false: \verb@None@, numeric zero of all types, empty sequences
|
||||
(strings, tuples and lists), and empty mappings (dictionaries). All
|
||||
other values are interpreted as true.
|
||||
|
||||
The operator \verb\not\ yields 1 if its argument is false, 0 otherwise.
|
||||
The operator \verb@not@ yields 1 if its argument is false, 0 otherwise.
|
||||
\opindex{not}
|
||||
|
||||
The condition $x ~\verb\and\~ y$ first evaluates $x$; if $x$ is false,
|
||||
The condition $x ~\verb@and@~ y$ first evaluates $x$; if $x$ is false,
|
||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
||||
value is returned.
|
||||
\opindex{and}
|
||||
|
||||
The condition $x ~\verb\or\~ y$ first evaluates $x$; if $x$ is true,
|
||||
The condition $x ~\verb@or@~ y$ first evaluates $x$; if $x$ is true,
|
||||
its value is returned; otherwise, $y$ is evaluated and the resulting
|
||||
value is returned.
|
||||
\opindex{or}
|
||||
|
||||
(Note that \verb\and\ and \verb\or\ do not restrict the value and type
|
||||
(Note that \verb@and@ and \verb@or@ do not restrict the value and type
|
||||
they return to 0 and 1, but rather return the last evaluated argument.
|
||||
This is sometimes useful, e.g. if \verb\s\ is a string that should be
|
||||
This is sometimes useful, e.g. if \verb@s@ is a string that should be
|
||||
replaced by a default value if it is empty, the expression
|
||||
\verb\s or 'foo'\ yields the desired value. Because \verb\not\ has to
|
||||
\verb@s or 'foo'@ yields the desired value. Because \verb@not@ has to
|
||||
invent a value anyway, it does not bother to return a value of the
|
||||
same type as its argument, so e.g. \verb\not 'foo'\ yields \verb\0\,
|
||||
not \verb\''\.)
|
||||
same type as its argument, so e.g. \verb@not 'foo'@ yields \verb@0@,
|
||||
not \verb@''@.)
|
||||
|
||||
Lambda forms (lambda expressions) have the same syntactic position as
|
||||
conditions. They are a shorthand to create anonymous functions; the
|
||||
expression \verb\lambda\ {\em arguments}\verb\:\ {\em condition}
|
||||
expression {\em {\tt lambda} arguments{\tt :} condition}
|
||||
yields a function object that behaves virtually identical to one
|
||||
defined with \verb\def\ {\em name}\verb\(\{\em arguments}\verb\) :
|
||||
return\ {\em condition}. See section \ref{function} for the syntax of
|
||||
defined with
|
||||
{\em {\tt def} name {\tt (}arguments{\tt ): return} condition}.
|
||||
See section \ref{function} for the syntax of
|
||||
parameter lists. Note that functions created with lambda forms cannot
|
||||
contain statements.
|
||||
\label{lambda}
|
||||
@ -686,4 +689,4 @@ tuple, but rather yields the value of that expression (condition).
|
||||
\indexii{trailing}{comma}
|
||||
|
||||
(To create an empty tuple, use an empty pair of parentheses:
|
||||
\verb\()\.)
|
||||
\verb@()@.)
|
||||
|
@ -14,7 +14,7 @@ the language, see the Python Tutorial. The Python Reference Manual
|
||||
gives a more formal definition of the language. (These manuals are not
|
||||
yet available in INFO or Texinfo format.)
|
||||
|
||||
Copyright (C) 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Copyright (C) 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
All Rights Reserved
|
||||
@ -43,7 +43,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@c The following two commands start the copyright page.
|
||||
@page
|
||||
@vskip 0pt plus 1filll
|
||||
Copyright @copyright{} 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Copyright @copyright{} 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
@center All Rights Reserved
|
||||
@ -77,7 +77,7 @@ the language, see the @cite{Python Tutorial}. The @cite{Python
|
||||
Reference Manual} gives a more formal definition of the language.
|
||||
(These manuals are not yet available in INFO or Texinfo format.)
|
||||
|
||||
This version corresponds roughly to Python version 1.0 (yet to be released).
|
||||
This version corresponds to Python version 1.0.2.
|
||||
|
||||
@end ifinfo
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
; load the new texinfo package (2.xx) if not installed by default
|
||||
; (setq load-path
|
||||
; (cons "/ufs/jh/lib/emacs/texinfo-2.14" load-path))
|
||||
(find-file "lib.texi")
|
||||
; (setq load-path (cons "/ufs/guido/lib/emacs/texinfo-2.14" load-path))
|
||||
(find-file "@lib.texi")
|
||||
(texinfo-all-menus-update t)
|
||||
(texinfo-all-menus-update t)
|
||||
|
@ -1 +1,2 @@
|
||||
#!/bin/sh
|
||||
sed -e 's/{\\ptt[ ]*\\char[ ]*'"'"'137}/_/g' <"$1" > "@$1" && mv "@$1" $1
|
||||
|
743
Doc/tut.tex
743
Doc/tut.tex
File diff suppressed because it is too large
Load Diff
743
Doc/tut/tut.tex
743
Doc/tut/tut.tex
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user