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

Skip to content

Commit 65a350d

Browse files
committed
SF bug #1076955: Tutorial corrections Part II
1 parent aa2b2aa commit 65a350d

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

Doc/tut/glossary.tex

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ \chapter{Glossary\label{glossary}}
4040

4141
The implicit conversion of an instance of one type to another during an
4242
operation which involves two arguments of the same type. For example,
43-
{}\code{int(3.15)} converts the floating point number to the integer,
43+
{}\code{int(3.15)} converts the floating point number to the integer
4444
{}\code{3}, but in {}\code{3+4.5}, each argument is of a different type (one
4545
int, one float), and both must be converted to the same type before they can
4646
be added or it will raise a {}\code{TypeError}. Coercion between two
@@ -169,7 +169,7 @@ \chapter{Glossary\label{glossary}}
169169
An object with fixed value. Immutable objects are numbers, strings or
170170
tuples (and more). Such an object cannot be altered. A new object
171171
has to be created if a different value has to be stored. They play an
172-
important role in places where a constant hash value is needed. For
172+
important role in places where a constant hash value is needed, for
173173
example as a key in a dictionary.
174174

175175
\index{integer division}
@@ -189,7 +189,7 @@ \chapter{Glossary\label{glossary}}
189189
\index{interactive}
190190
\item[interactive]
191191
Python has an interactive interpreter which means that you can try out
192-
things and directly see its result. Just launch \code{python} with no
192+
things and immediately see their results. Just launch \code{python} with no
193193
arguments (possibly by selecting it from your computer's main menu).
194194
It is a very powerful way to test out new ideas or inspect modules and
195195
packages (remember \code{help(x)}).
@@ -235,7 +235,7 @@ \chapter{Glossary\label{glossary}}
235235
(such as a \class{list}) produces a fresh new iterator each time you
236236
pass it to the \function{iter()} function or use it in a
237237
{}\keyword{for} loop. Attempting this with an iterator will just
238-
return the same exhausted iterator object from the second iteration
238+
return the same exhausted iterator object used in the previous iteration
239239
pass, making it appear like an empty container.
240240

241241
\index{list comprehension}
@@ -245,7 +245,15 @@ \chapter{Glossary\label{glossary}}
245245
\% x for x in range(256) if x \% 2 == 0]} generates a list of strings
246246
containing hex numbers (0x..) that are even and in the range from 0 to 255.
247247
The \keyword{if} clause is optional. If omitted, all elements in
248-
{}\code{range(256)} are processed in that case.
248+
{}\code{range(256)} are processed.
249+
250+
251+
\index{LBYL}
252+
\item[LBYL]
253+
Look before you leap. This coding style explicitly tests for
254+
pre-conditions before making calls or lookups. This style contrasts
255+
with the \emph{EAFP} approach and is characterized by the presence of
256+
many \keyword{if} statements.
249257

250258
\index{mapping}
251259
\item[mapping]
@@ -265,13 +273,6 @@ \chapter{Glossary\label{glossary}}
265273
tracking object creation, implementing singletons, and many other
266274
tasks.
267275

268-
\index{LBYL}
269-
\item[LBYL]
270-
Look before you leap. This coding style explicitly tests for
271-
pre-conditions before making calls or lookups. This style contrasts
272-
with the \emph{EAFP} approach and is characterized the presence of
273-
many \keyword{if} statements.
274-
275276
\index{mutable}
276277
\item[mutable]
277278
Mutable objects can change their value but keep their \function{id()}.
@@ -280,8 +281,8 @@ \chapter{Glossary\label{glossary}}
280281
\index{namespace}
281282
\item[namespace]
282283
The place where a variable is stored. Namespaces are implemented as
283-
dictionary. There is the local, global and builtins namespace and the
284-
nested namespaces in objects (in methods). Namespaces support
284+
dictionaries. There are the local, global and builtin namespaces
285+
as well asnested namespaces in objects (in methods). Namespaces support
285286
modularity by preventing naming conflicts. For instance, the
286287
functions \function{__builtin__.open()} and \function{os.open()} are
287288
distinguished by their namespaces. Namespaces also aid readability
@@ -312,7 +313,7 @@ \chapter{Glossary\label{glossary}}
312313

313314
\index{Python3000}
314315
\item[Python3000]
315-
A mythical python release, allowed not to be backward compatible, with
316+
A mythical python release, not required be backward compatible, with
316317
telepathic interface.
317318

318319
\index{__slots__}
@@ -321,7 +322,7 @@ \chapter{Glossary\label{glossary}}
321322
pre-declaring space for instance attributes and eliminating instance
322323
dictionaries. Though popular, the technique is somewhat tricky to get
323324
right and is best reserved for rare cases where there are large
324-
numbers of instances in a memory critical application.
325+
numbers of instances in a memory-critical application.
325326

326327
\index{sequence}
327328
\item[sequence]

Doc/tut/tut.tex

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ \section{Dictionaries \label{dictionaries}}
21752175
\begin{verbatim}
21762176
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
21772177
{'sape': 4139, 'jack': 4098, 'guido': 4127}
2178-
>>> dict([(x, x**2) for x in (2, 4, 6)) # use a list comprehension
2178+
>>> dict([(x, x**2) for x in (2, 4, 6)]) # use a list comprehension
21792179
{2: 4, 4: 16, 6: 36}
21802180
\end{verbatim}
21812181

@@ -4193,6 +4193,7 @@ \subsection{Multiple Inheritance \label{multiple}}
41934193
variables'' or data attributes used by the common base class), it is
41944194
not clear that these semantics are in any way useful.
41954195
4196+
%% XXX Add rules for new-style MRO?
41964197
41974198
\section{Private Variables \label{private}}
41984199
@@ -4201,9 +4202,9 @@ \section{Private Variables \label{private}}
42014202
leading underscores, at most one trailing underscore) is textually
42024203
replaced with \code{_classname__spam}, where \code{classname} is the
42034204
current class name with leading underscore(s) stripped. This mangling
4204-
is done without regard of the syntactic position of the identifier, so
4205+
is done without regard to the syntactic position of the identifier, so
42054206
it can be used to define class-private instance and class variables,
4206-
methods, as well as globals, and even to store instance variables
4207+
methods, variables stored in globals, and even variables stored in instances.
42074208
private to this class on instances of \emph{other} classes. Truncation
42084209
may occur when the mangled name would be longer than 255 characters.
42094210
Outside classes, or when the class name consists of only underscores,
@@ -4232,7 +4233,7 @@ \section{Private Variables \label{private}}
42324233
\section{Odds and Ends \label{odds}}
42334234
42344235
Sometimes it is useful to have a data type similar to the Pascal
4235-
``record'' or C ``struct'', bundling together a couple of named data
4236+
``record'' or C ``struct'', bundling together a few named data
42364237
items. An empty class definition will do nicely:
42374238
42384239
\begin{verbatim}
@@ -4251,7 +4252,7 @@ \section{Odds and Ends \label{odds}}
42514252
can often be passed a class that emulates the methods of that data
42524253
type instead. For instance, if you have a function that formats some
42534254
data from a file object, you can define a class with methods
4254-
\method{read()} and \method{readline()} that gets the data from a string
4255+
\method{read()} and \method{readline()} that get the data from a string
42554256
buffer instead, and pass it as an argument.% (Unfortunately, this
42564257
%technique has its limitations: a class can't define operations that
42574258
%are accessed by special syntax such as sequence subscripting or
@@ -4261,7 +4262,7 @@ \section{Odds and Ends \label{odds}}
42614262
42624263
42634264
Instance method objects have attributes, too: \code{m.im_self} is the
4264-
object of which the method is an instance, and \code{m.im_func} is the
4265+
instance object with the method \method{m}, and \code{m.im_func} is the
42654266
function object corresponding to the method.
42664267
42674268
@@ -4530,7 +4531,7 @@ \section{File Wildcards\label{file-wildcards}}
45304531
45314532
\section{Command Line Arguments\label{command-line-arguments}}
45324533
4533-
Common utility scripts often invoke processing command line arguments.
4534+
Common utility scripts often need to process command line arguments.
45344535
These arguments are stored in the
45354536
\ulink{\module{sys}}{../lib/module-sys.html}\ module's \var{argv}
45364537
attribute as a list. For instance the following output results from
@@ -4557,7 +4558,7 @@ \section{Error Output Redirection and Program Termination\label{stderr}}
45574558
messages to make them visible even when \var{stdout} has been redirected:
45584559
45594560
\begin{verbatim}
4560-
>>> sys.stderr.write('Warning, log file not found starting a new one')
4561+
>>> sys.stderr.write('Warning, log file not found starting a new one\n')
45614562
Warning, log file not found starting a new one
45624563
\end{verbatim}
45634564
@@ -4636,7 +4637,7 @@ \section{Internet Access\label{internet-access}}
46364637
>>> import smtplib
46374638
>>> server = smtplib.SMTP('localhost')
46384639
>>> server.sendmail('[email protected]', '[email protected]',
4639-
"""To: jceasar@example.org
4640+
"""To: jcaesar@example.org
46404641
46414642
46424643
Beware the Ides of March.
@@ -4660,8 +4661,8 @@ \section{Dates and Times\label{dates-and-times}}
46604661
>>> now = date.today()
46614662
>>> now
46624663
datetime.date(2003, 12, 2)
4663-
>>> now.strftime("%m-%d-%y or %d%b %Y is a %A on the %d day of %B")
4664-
'12-02-03 or 02Dec 2003 is a Tuesday on the 02 day of December'
4664+
>>> now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
4665+
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'
46654666
46664667
# dates support calendar arithmetic
46674668
>>> birthday = date(1964, 7, 31)
@@ -4691,8 +4692,8 @@ \section{Data Compression\label{data-compression}}
46914692
37
46924693
>>> zlib.decompress(t)
46934694
'witch which has which witches wrist watch'
4694-
>>> zlib.crc32(t)
4695-
-1438085031
4695+
>>> zlib.crc32(s)
4696+
226805979
46964697
\end{verbatim}
46974698
46984699
@@ -5219,7 +5220,7 @@ \section{Decimal Floating Point Arithmetic\label{decimal-fp}}
52195220
\chapter{What Now? \label{whatNow}}
52205221
52215222
Reading this tutorial has probably reinforced your interest in using
5222-
Python --- you should be eager to apply Python to solve your
5223+
Python --- you should be eager to apply Python to solving your
52235224
real-world problems. Now what should you do?
52245225
52255226
You should read, or at least page through, the
@@ -5382,7 +5383,7 @@ \section{Key Bindings \label{keyBindings}}
53825383
this deletes the names it creates once they are no longer needed; this
53835384
is done since the startup file is executed in the same namespace as
53845385
the interactive commands, and removing the names avoids creating side
5385-
effects in the interactive environments. You may find it convenient
5386+
effects in the interactive environment. You may find it convenient
53865387
to keep some of the imported modules, such as
53875388
\ulink{\module{os}}{../lib/module-os.html}, which turn
53885389
out to be needed in most sessions with the interpreter.
@@ -5474,7 +5475,7 @@ \chapter{Floating Point Arithmetic: Issues and Limitations\label{fp-issues}}
54745475
54755476
and so on. No matter how many digits you're willing to write down, the
54765477
result will never be exactly 1/3, but will be an increasingly better
5477-
approximation to 1/3.
5478+
approximation of 1/3.
54785479
54795480
In the same way, no matter how many base 2 digits you're willing to
54805481
use, the decimal value 0.1 cannot be represented exactly as a base 2
@@ -5520,7 +5521,7 @@ \chapter{Floating Point Arithmetic: Issues and Limitations\label{fp-issues}}
55205521
\var{x}, but rounding to 16 digits is not enough to make that true.
55215522
55225523
Note that this is in the very nature of binary floating-point: this is
5523-
not a bug in Python, it is not a bug in your code either, and you'll
5524+
not a bug in Python, it is not a bug in your code either. You'll
55245525
see the same kind of thing in all languages that support your
55255526
hardware's floating-point arithmetic (although some languages may
55265527
not \emph{display} the difference by default, or in all output modes).
@@ -5634,7 +5635,7 @@ \section{Representation Error
56345635
\code{< 2**53}), the best value for \var{N} is 56:
56355636

56365637
\begin{verbatim}
5637-
>>> 2L**52
5638+
>>> 2**52
56385639
4503599627370496L
56395640
>>> 2L**53
56405641
9007199254740992L

0 commit comments

Comments
 (0)