@@ -38,7 +38,7 @@ \chapter*{Front Matter\label{front}}
3838and additional documentation.
3939
4040The Python interpreter is easily extended with new functions and data
41- types implemented in \C {} or \Cpp {} (or other languages callable from \C {} ).
41+ types implemented in C or \Cpp {} (or other languages callable from C ).
4242Python is also suitable as an extension language for customizable
4343applications.
4444
@@ -50,8 +50,8 @@ \chapter*{Front Matter\label{front}}
5050For a description of standard objects and modules, see the
5151\emph {Python Library Reference } document. The \emph {Python Reference
5252Manual } gives a more formal definition of the language. To write
53- extensions in \C {} or \Cpp {}, read the \emph {Extending and Embedding } and
54- \emph {Python/\C {} API } manuals. There are also several books covering
53+ extensions in C or \Cpp {}, read the \emph {Extending and Embedding } and
54+ \emph {Python/C API } manuals. There are also several books covering
5555Python in depth.
5656
5757This tutorial does not attempt to be comprehensive and cover every
@@ -72,15 +72,15 @@ \chapter{Whetting Your Appetite \label{intro}}
7272If you ever wrote a large shell script, you probably know this
7373feeling: you'd love to add yet another feature, but it's already so
7474slow, and so big, and so complicated; or the feature involves a system
75- call or other function that is only accessible from \C {} \ldots Usually
75+ call or other function that is only accessible from C \ldots Usually
7676the problem at hand isn't serious enough to warrant rewriting the
77- script in \C {} ; perhaps the problem requires variable-length strings or
77+ script in C ; perhaps the problem requires variable-length strings or
7878other data types (like sorted lists of file names) that are easy in
79- the shell but lots of work to implement in \C {} , or perhaps you're not
80- sufficiently familiar with \C {} .
79+ the shell but lots of work to implement in C , or perhaps you're not
80+ sufficiently familiar with C .
8181
82- Another situation: perhaps you have to work with several \C {} libraries,
83- and the usual \C {} write/compile/test/re-compile cycle is too slow. You
82+ Another situation: perhaps you have to work with several C libraries,
83+ and the usual C write/compile/test/re-compile cycle is too slow. You
8484need to develop software more quickly. Possibly perhaps you've
8585written a program that could use an extension language, and you don't
8686want to design a language, write and debug an interpreter for it, then
@@ -89,10 +89,10 @@ \chapter{Whetting Your Appetite \label{intro}}
8989In such cases, Python may be just the language for you. Python is
9090simple to use, but it is a real programming language, offering much
9191more structure and support for large programs than the shell has. On
92- the other hand, it also offers much more error checking than \C {} , and,
92+ the other hand, it also offers much more error checking than C , and,
9393being a \emph {very-high-level language }, it has high-level data types
9494built in, such as flexible arrays and dictionaries that would cost you
95- days to implement efficiently in \C {} . Because of its more general data
95+ days to implement efficiently in C . Because of its more general data
9696types Python is applicable to a much larger problem domain than
9797\emph {Awk } or even \emph {Perl }, yet many things are at least as easy
9898in Python as in those languages.
@@ -112,7 +112,7 @@ \chapter{Whetting Your Appetite \label{intro}}
112112It is also a handy desk calculator.
113113
114114Python allows writing very compact and readable programs. Programs
115- written in Python are typically much shorter than equivalent \C {}
115+ written in Python are typically much shorter than equivalent C
116116programs, for several reasons:
117117\begin {itemize }
118118\item
@@ -125,12 +125,12 @@ \chapter{Whetting Your Appetite \label{intro}}
125125no variable or argument declarations are necessary.
126126\end {itemize }
127127
128- Python is \emph {extensible }: if you know how to program in \C {} it is easy
128+ Python is \emph {extensible }: if you know how to program in C it is easy
129129to add a new built-in function or module to the interpreter, either to
130130perform critical operations at maximum speed, or to link Python
131131programs to libraries that may only be available in binary form (such
132132as a vendor-specific graphics library). Once you are really hooked,
133- you can link the Python interpreter into an application written in \C {}
133+ you can link the Python interpreter into an application written in C
134134and use it as an extension or command language for that application.
135135
136136By the way, the language is named after the BBC show `` Monty Python's
@@ -244,7 +244,7 @@ \subsection{Interactive Mode \label{interactive}}
244244
245245\begin {verbatim }
246246python
247- Python 1.5b1 (#1, Dec 3 1997 , 00:02:06) [GCC 2.7.2.2 ] on sunos5
247+ Python 1.5.2b2 (#1, Feb 28 1999 , 00:02:06) [GCC 2.8.1 ] on sunos5
248248Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
249249>>>
250250\end {verbatim }
@@ -311,13 +311,14 @@ \subsection{The Interactive Startup File \label{startup}}
311311
312312If you want to read an additional start-up file from the current
313313directory, you can program this in the global start-up file,
314- e.g.\ \samp {execfile('.pythonrc')}\indexii {.pythonrc.py}{file}. If
314+ e.g.\ \samp {execfile('.pythonrc.py ')}\indexii {.pythonrc.py}{file}. If
315315you want to use the startup file in a script, you must do this
316316explicitly in the script:
317317
318318\begin {verbatim }
319319import os
320- if os.path.isfile(os.environ['PYTHONSTARTUP']):
320+ if os.environ.get('PYTHONSTARTUP') \
321+ and os.path.isfile(os.environ['PYTHONSTARTUP']):
321322 execfile(os.environ['PYTHONSTARTUP'])
322323\end {verbatim }
323324
@@ -347,7 +348,7 @@ \subsection{Numbers \label{numbers}}
347348The interpreter acts as a simple calculator: you can type an
348349expression at it and it will write the value. Expression syntax is
349350straightforward: the operators \code {+}, \code {-}, \code {*} and \code {/}
350- work just like in most other languages (e.g., Pascal or \C {} ); parentheses
351+ work just like in most other languages (e.g., Pascal or C ); parentheses
351352can be used for grouping. For example:
352353
353354\begin {verbatim }
@@ -367,7 +368,7 @@ \subsection{Numbers \label{numbers}}
367368-3
368369\end {verbatim }
369370
370- Like in \C {} , the equal sign (\character {=}) is used to assign a value to a
371+ Like in C , the equal sign (\character {=}) is used to assign a value to a
371372variable. The value of an assignment is not written:
372373
373374\begin {verbatim }
@@ -564,7 +565,7 @@ \subsection{Strings \label{strings}}
564565SyntaxError: invalid syntax
565566\end {verbatim }
566567
567- Strings can be subscripted (indexed); like in \C {} , the first character
568+ Strings can be subscripted (indexed); like in C , the first character
568569of a string has subscript (index) 0. There is no separate character
569570type; a character is simply a string of size one. Like in Icon,
570571substrings can be specified with the \emph {slice notation }: two indices
@@ -804,12 +805,12 @@ \section{First Steps Towards Programming \label{firstSteps}}
804805
805806\item
806807The \keyword {while} loop executes as long as the condition (here:
807- \code {b < 10}) remains true. In Python, like in \C {} , any non-zero
808+ \code {b < 10}) remains true. In Python, like in C , any non-zero
808809integer value is true; zero is false. The condition may also be a
809810string or list value, in fact any sequence; anything with a non-zero
810811length is true, empty sequences are false. The test used in the
811812example is a simple comparison. The standard comparison operators are
812- written the same as in \C {} : \code {<}, \code {>}, \code {==}, \code {<=},
813+ written the same as in C : \code {<}, \code {>}, \code {==}, \code {<=},
813814\code {>=} and \code {!=}.
814815
815816\item
@@ -893,10 +894,10 @@ \section{\keyword{if} Statements \label{if}}
893894\section {\keyword {for} Statements \label {for } }
894895
895896The \keyword {for}\stindex {for} statement in Python differs a bit from
896- what you may be used to in \C {} or Pascal. Rather than always
897+ what you may be used to in C or Pascal. Rather than always
897898iterating over an arithmetic progression of numbers (like in Pascal),
898899or giving the user the ability to define both the iteration step and
899- halting condition (as \C {} ), Python's \keyword {for}\stindex {for}
900+ halting condition (as C ), Python's \keyword {for}\stindex {for}
900901statement iterates over the items of any sequence (e.g., a list or a
901902string), in the order that they appear in the sequence. For example
902903(no pun intended):
@@ -974,10 +975,10 @@ \section{\keyword{break} and \keyword{continue} Statements, and
974975 \keyword {else} Clauses on Loops
975976 \label {break } }
976977
977- The \keyword {break} statement, like in \C {} , breaks out of the smallest
978+ The \keyword {break} statement, like in C , breaks out of the smallest
978979enclosing \keyword {for} or \keyword {while} loop.
979980
980- The \keyword {continue} statement, also borrowed from \C {} , continues
981+ The \keyword {continue} statement, also borrowed from C , continues
981982with the next iteration of the loop.
982983
983984Loop statements may have an \code {else} clause; it is executed when
@@ -1085,7 +1086,7 @@ \section{Defining Functions \label{functions}}
10851086\end {verbatim }
10861087
10871088You might object that \code {fib} is not a function but a procedure. In
1088- Python, like in \C {} , procedures are just functions that don't return a
1089+ Python, like in C , procedures are just functions that don't return a
10891090value. In fact, technically speaking, procedures do return a value,
10901091albeit a rather boring one. This value is called \code {None} (it's a
10911092built-in name). Writing the value \code {None} is normally suppressed by
@@ -1430,7 +1431,7 @@ \subsection{Functional Programming Tools \label{functional}}
14301431example, to compute some primes:
14311432
14321433\begin {verbatim }
1433- >>> def f(x): return x% 2 != 0 and x% 3 != 0
1434+ >>> def f(x): return x % 2 != 0 and x % 3 != 0
14341435...
14351436>>> filter(f, range(2, 25))
14361437[5, 7, 11, 13, 17, 19, 23]
@@ -1698,7 +1699,7 @@ \section{More on Conditions \label{conditions}}
16981699'Trondheim'
16991700\end {verbatim }
17001701
1701- Note that in Python, unlike \C {} , assignment cannot occur inside expressions.
1702+ Note that in Python, unlike C , assignment cannot occur inside expressions.
17021703
17031704\section {Comparing Sequences and Other Types \label {comparing } }
17041705
@@ -1974,8 +1975,9 @@ \section{Standard Modules \label{standardModules}}
19741975\module {amoeba} module is only provided on systems that somehow
19751976support Amoeba primitives. One particular module deserves some
19761977attention: \module {sys}\refstmodindex {sys}, which is built into every
1977- Python interpreter. The variables \code {sys.ps1} and \code {sys.ps2}
1978- define the strings used as primary and secondary prompts:
1978+ Python interpreter. The variables \code {sys.ps1} and
1979+ \code {sys.ps2} define the strings used as primary and secondary
1980+ prompts:
19791981
19801982\begin {verbatim }
19811983>>> import sys
@@ -1992,13 +1994,11 @@ \section{Standard Modules \label{standardModules}}
19921994These two variables are only defined if the interpreter is in
19931995interactive mode.
19941996
1995- The variable
1996- \code {sys.path}
1997- is a list of strings that determine the interpreter's search path for
1998- modules.
1999- It is initialized to a default path taken from the environment variable
2000- \envvar {PYTHONPATH}, or from a built-in default if \envvar {PYTHONPATH}
2001- is not set. You can modify it using standard list operations, e.g.:
1997+ The variable \code {sys.path} is a list of strings that determine the
1998+ interpreter's search path for modules. It is initialized to a default
1999+ path taken from the environment variable \envvar {PYTHONPATH}, or from
2000+ a built-in default if \envvar {PYTHONPATH} is not set. You can modify
2001+ it using standard list operations, e.g.:
20022002
20032003\begin {verbatim }
20042004>>> import sys
@@ -2279,7 +2279,7 @@ \section{Fancier Output Formatting \label{formatting}}
22792279for padding strings to a given column width;
22802280these will be discussed shortly. The second way is to use the
22812281\code {\% } operator with a string as the left argument. \code {\% }
2282- interprets the left argument as a \C {} \cfunction {sprintf()}-style
2282+ interprets the left argument as a C \cfunction {sprintf()}-style
22832283format string to be applied to the right argument, and returns the
22842284string resulting from this formatting operation.
22852285
@@ -2391,18 +2391,18 @@ \section{Fancier Output Formatting \label{formatting}}
23912391Sjoerd ==> 4127
23922392\end {verbatim }
23932393
2394- Most formats work exactly as in \C {} and require that you pass the proper
2394+ Most formats work exactly as in C and require that you pass the proper
23952395type; however, if you don't you get an exception, not a core dump.
23962396The \code {\% s} format is more relaxed: if the corresponding argument is
23972397not a string object, it is converted to string using the
23982398\function {str()} built-in function. Using \code {*} to pass the width
23992399or precision in as a separate (integer) argument is supported. The
2400- \C {} formats \code {\% n} and \code {\% p} are not supported.
2400+ C formats \code {\% n} and \code {\% p} are not supported.
24012401
24022402If you have a really long format string that you don't want to split
24032403up, it would be nice if you could reference the variables to be
24042404formatted by name instead of by position. This can be done by using
2405- an extension of \C {} formats using the form \code {\% (name)format}, e.g.
2405+ an extension of C formats using the form \code {\% (name)format}, e.g.
24062406
24072407\begin {verbatim }
24082408>>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
@@ -2446,7 +2446,7 @@ \section{Reading and Writing Files \label{files}}
24462446\ASCII {} text files, but it'll corrupt binary data like that in JPEGs or
24472447\file {.EXE} files. Be very careful to use binary mode when reading and
24482448writing such files. (Note that the precise semantics of text mode on
2449- the Macintosh depends on the underlying \C {} library being used.)
2449+ the Macintosh depends on the underlying C library being used.)
24502450
24512451\subsection {Methods of File Objects \label {fileMethods } }
24522452
@@ -3144,9 +3144,9 @@ \subsection{Method Objects \label{methodObjects}}
31443144\end {verbatim }
31453145
31463146In our example, this will return the string \code {'hello world'}.
3147- However, it is not necessary to call a method right away: \code {x.f}
3148- is a method object, and can be stored away and called at a later
3149- moment, for example:
3147+ However, it is not necessary to call a method right away:
3148+ \code {x.f} is a method object, and can be stored away and called at a
3149+ later time. For example:
31503150
31513151\begin {verbatim }
31523152xf = x.f
@@ -3201,9 +3201,9 @@ \section{Random Remarks \label{remarks}}
32013201usable to implement pure abstract data types. In fact, nothing in
32023202Python makes it possible to enforce data hiding --- it is all based
32033203upon convention. (On the other hand, the Python implementation,
3204- written in \C {} , can completely hide implementation details and control
3204+ written in C , can completely hide implementation details and control
32053205access to an object if necessary; this can be used by extensions to
3206- Python written in \C {} .)
3206+ Python written in C .)
32073207
32083208
32093209Clients should use data attributes with care --- clients may mess up
@@ -3480,7 +3480,7 @@ \section{Private Variables \label{private}}
34803480\section {Odds and Ends \label {odds } }
34813481
34823482Sometimes it is useful to have a data type similar to the Pascal
3483- `` record'' or \C {} `` struct'' , bundling together a couple of named data
3483+ `` record'' or C `` struct'' , bundling together a couple of named data
34843484items. An empty class definition will do nicely, e.g.:
34853485
34863486\begin {verbatim }
@@ -3560,9 +3560,9 @@ \subsection{Exceptions Can Be Classes \label{exceptionClasses}}
35603560 print "B"
35613561\end {verbatim }
35623562
3563- Note that if the except clauses were reversed (with \samp {except B}
3564- first), it would have printed B, B, B --- the first matching except
3565- clause is triggered.
3563+ Note that if the except clauses were reversed (with
3564+ \samp {except B} first), it would have printed B, B, B --- the first
3565+ matching except clause is triggered.
35663566
35673567When an error message is printed for an unhandled exception which is a
35683568class, the class name is printed, then a colon and a space, and
@@ -3579,7 +3579,7 @@ \chapter{What Now? \label{whatNow}}
35793579which gives complete (though terse) reference material about types,
35803580functions, and modules that can save you a lot of time when writing
35813581Python programs. The standard Python distribution includes a
3582- \emph {lot } of code in both \C {} and Python; there are modules to read
3582+ \emph {lot } of code in both C and Python; there are modules to read
35833583\UNIX {} mailboxes, retrieve documents via HTTP, generate random
35843584numbers, parse command-line options, write CGI programs, compress
35853585data, and a lot more; skimming through the Library Reference will give
@@ -3708,9 +3708,9 @@ \section{Key Bindings \label{keyBindings}}
37083708
37093709Automatic completion of variable and module names is optionally
37103710available. To enable it in the interpreter's interactive mode, add
3711- the following to your \file {\$ HOME/.pythonrc} file:% $ <- bow to font-lock
3712- \indexii {.pythonrc.py}{file}%
3713- \refstmodindex {rlcompleter}%
3711+ the following to your \file {\$ HOME/.pythonrc.py } file:% $ <- bow to font-lock
3712+ \indexii {.pythonrc.py}{file}
3713+ \refstmodindex {rlcompleter}
37143714\refbimodindex {readline}
37153715
37163716\begin {verbatim }
@@ -3741,4 +3741,3 @@ \section{Commentary \label{commentary}}
37413741% XXX Lele Gaifax's readline module, which adds name completion...
37423742
37433743\end {document }
3744-
0 commit comments