[ python-Bugs-971747 ] Wrong indentation of example code in tutorial

SourceForge.net noreply at sourceforge.net
Sat Jun 12 15:43:54 EDT 2004


Bugs item #971747, was opened at 2004-06-12 10:44
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=971747&group_id=5470

Category: Documentation
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Grégoire Dooms (dooms)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Wrong indentation of example code in tutorial

Initial Comment:
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. 
 

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-06-12 14:43

Message:
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.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=971747&group_id=5470



More information about the Python-bugs-list mailing list