PEP 276 -- What else could iter(5) mean?
Huaiyu Zhu
huaiyu at gauss.almadan.ibm.com
Wed Mar 6 20:21:38 EST 2002
>James_Althoff at i2.com writes:
>
>> > [f(x) for x in (4 in 3) in (2 in 3) if x in (x+1 in x*2)] # just for fun.
>> But just to make sure I understand your point, I guess you are saying the
>> above is bad because today's equivalent is more clear?
>>
>> [f(x) for x in range((4 in range(3))) in range((2 in range(3))) if x in
>> range((x+1 in range(x*2)))]
No. Today's equivalence is
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: iterable argument required
>> Can you suggest a less contrived example that might be a problem?
Bernhard Herzog <bh at intevation.de> wrote:
>
>x, = 1
>
>would assign 0 to x instead of raising an error.
Exactly. And one can imagine a situation where this may build up to the
above contrived example if the error is not detected earlier. Even though
this proposal does not directly lead to 3 == (0,1,2), it does imply that you
can use an integer in majority of cases where a sequence is required. Eg:
f(*6)
a,b,c = 3
2 in 4
for a, b in 2, 2, 2, 2: print a, b
3[2][1][0]
Huaiyu
More information about the Python-list
mailing list