Status of PEP's?
Jeff Shannon
jeff at ccvcorp.com
Thu Mar 7 19:57:35 EST 2002
Jesse W wrote:
> The ugly posibiliites:
> for i in 5:
> print i*2,
> #Would print: 8 6 4 2 0
> #Why? What posible sense would this make?
No, it would print: 0 2 4 6 8
It doesn't make any less sense to do this than it does to say
for i in xrange(5):
print i * 2
These two loops would become equivalent.
> var=-2
> for i in var:
> print i
> #Would generate an error of some kind because var is negative.
Well, the same thing happens with 'for i in range(var):' in this case.
Actually, range() on a negative number returns an empty list; I'd presume
that iter() on a negative number should immediately raise StopIteration.
> #Or, look at this:
> def foo(var):
> var=int(var)
> var=var*5
> var=var/3
> var+= 12.3
> for i in var*2:
> print i
> #Will this generate an error?
This may actually be a valid point -- range(float) currently is equivalent to
range(int(float)), but PEP 276 doesn't propose any new behavior for floats,
so this should raise an exception. Still, I think that it's reasonable to
expect for programmers to not try to iterate/loop over a float value.
> I am sure that others can think of more unpleasent posibilities.
> The basic problem is that the proposal is simply too broad.
One of the things that really disturbs me about this proposal, is the
possibility of integers taking on a new meaning in other contexts than loops,
where the iterator protocol is used but this behavior might *not* be
'natural' for integers. I don't know of any other such contexts off the top
of my head, except for if statements. Personally, I see 'if x in 5' being a
wonderful chance to create all sorts of confusion, but others may disagree.
(Of course, I see 'for x in 5' as being likely to create confusion, and
others *obviously* disagree with that. <wink>)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list