This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Wrong indentation of example code in tutorial
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: dooms, rhettinger
Priority: normal Keywords:

Created on 2004-06-12 15:44 by dooms, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tut.patch dooms, 2004-06-12 15:44 context diff of python2.3-2.3.3/Doc/tut/tut.tex
Messages (3)
msg21169 - (view) Author: Grégoire Dooms (dooms) Date: 2004-06-12 15:44
section 9.9: 
on line 4286 (tut.tex python 2.3.3): 
>>> class Reverse: 
    "Iterator for looping over a sequence backwards" 
    def __init__(self, data): 
        self.data = data 
        self.index = len(data) 
    def __iter__(self): 
        return self 
    def next(self): 
        if self.index == 0: 
            raise StopIteration 
        self.index = self.index - 1 
        return self.data[self.index] 
 
>>> for char in Reverse('spam'): 
        print char 
 
m 
a 
p 
s 
 
This is not conformant with the other exmaples (either 
script or interactive). It looks like this snippet was a script 
at first and was wrongly converted into an interactive 
session by prepending >>> on the first line. 
 
Prompt only problem in the next example: 
line 4319: 
>>> def reverse(data): 
        for index in range(len(data)-1, -1, -1): 
            yield data[index] 
 
>>> for char in reverse('golf'): 
        print char 
Indentation is good but the sys.ps2 prompt is missing. 
 
Now an indentation only problem (section 10.7) 
line 4505: 
>>> import urllib2 
>>> for line in 
urllib2.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'): 
... if 'EST' in line:      # look for Eastern Standard Time 
...     print line 
 
The if and print lines need an additional indentation 
level. This last one is already fixed in the 
http://www.python.org/dev/devel/doc/tut/ version. 
 
msg21170 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-06-12 19:43
Logged In: YES 
user_id=80475

Backport the fix for the urllib example.  The
Reverse('spam') example was already fixed and backported.

The decision to omit the '...' PS2 prompt was intentional. 
Using the IDLE style '   ' PS2 prompt makes these examples
easier to cut and paste so the reader can try them out
interactively.  Also, I find them to be more readable. 
Practicality trumps smaller concerns about putting every
example in exactly the same format.
msg21171 - (view) Author: Grégoire Dooms (dooms) Date: 2004-06-13 07:27
Logged In: YES 
user_id=846867

The Reverse('spam') example is still not fixed according to 
CVS tut.tex 1.196.8.20: either the IDLE PS2 prompt or the 
indentation is missing: the docstring and the method defs are 
alined with the c in class. 
 
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40390
2004-06-12 15:44:26doomscreate