Thought on PEP 204 and 276
holger krekel
pyth at devel.trillke.net
Mon May 27 15:33:47 EDT 2002
Steve Horne wrote:
>
> I can't help being disappointed that PEP 204 was rejected. To me,
>
> for i in [0:10] :
>
> is much more intuitive than the PEP 276 version
>
> for i in 10 :
I must say, i dislike both :-)
The reasoning in PEP 276 is IMO somewhat superseded by PEP279 (enumerate).
For example in PEP276 this code is given:
for rowcount in range(table.getRowCount()):
print table.getValueAt(rowcount, 0)
where
for rowcount in table.getRowCount():
print table.getValueAt(rowcount,0)
would be the PEP-solution. With enumerate you have
for i,item in table:
# use item
table.setValueAt(i, ***)
in many cases (where table is iterable that is).
I think that 'for i in 10:' is hardly ever used literally.
By far the most common case is:
for i in xrange(len(somelist)):
item=somelist[i]
# use it
somelist[i]=newvalue
which becomes:
for i,item in enumerate(somelist):
# use item
somelist[i]=newvalue
So i don't see many applications for PEP276 anymore.
regards,
holger
More information about the Python-list
mailing list