[ python-Bugs-971747 ] Wrong indentation of example code in tutorial
SourceForge.net
noreply at sourceforge.net
Sat Jun 12 11:44:27 EDT 2004
Bugs item #971747, was opened at 2004-06-12 15:44
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=971747&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Grégoire Dooms (dooms)
Assigned to: Nobody/Anonymous (nobody)
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.
----------------------------------------------------------------------
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