[issue11889] 'enumerate' 'start' parameter documentation is confusing
Peter Hammer
report at bugs.python.org
Wed May 25 05:22:38 CEST 2011
Peter Hammer <phammer at cardious.com> added the comment:
"""
Changing the 'enumerate' doc string text from:
| (0, seq[0]), (1, seq[1]), (2, seq[2]), ...
to:
| (start, seq[0]), (start+1, seq[1]), (start+2, seq[2]), ...
would completely disambiguate the doc string at the modest cost of
sixteen additional characters, a small price for pellucid clarity.
The proposed changes to the formal documentation also seem to me to
be prudent, and I hope at this late writing, they have already been
committed.
I conclude with a code fragment for the edification of R. David Murray.
"""
class numerate(object):
"""
A demonstration of a plausible incorrect interpretation of
the 'enumerate' function's doc string and documentation.
"""
def __init__(self,seq,start=0):
self.seq=seq; self.index=start-1
try:
if seq.next: pass #test for iterable
for i in xrange(start): self.seq.next()
except:
if type(seq)==dict: self.seq=seq.keys()
self.seq=iter(self.seq[start:])
def next(self):
self.index+=1
return self.index,self.seq.next()
def __iter__(self): return self
if __name__ == "__main__":
#s=['spring','summer','autumn','winter']
s={'spring':'a','summer':'b','autumn':'c','winter':'d'}
#s=enumerate(s)#,2)
s=numerate(s,2)
for t in s: print t
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11889>
_______________________________________
More information about the Python-bugs-list
mailing list