PEP 276 (was Re: Status of PEP's?)

Bengt Richter bokr at oz.net
Thu Feb 28 19:37:53 EST 2002


[just posted]
On 28 Feb 2002 05:57:05 -0800, aahz at panix.com (Aahz Maruch) wrote:
>[posted & e-mailed]
>
>In article <mailman.1014854027.3045.python-list at python.org>,
> <James_Althoff at i2.com> wrote:
>>
>>Rather than restart the entire debate on PEP 276, please send me
>>suggestions for specific changes to the PEP.
>
>My primary complaint about the PEP is that the following idiom is
>awkward, ugly, and prone to misunderstanding:
>
>    if i in 5:
>        ...
>
>Please add this to your list of objections.

how about

    if i in [:5]:  # (colon required to specify slice vs list)

The implication is an anonymous slice of xrange(sys.maxint+1)
(if that were legal).

<aside>
BTW, how do you specify a for-count ending in sys.maxint?

 >>> for i in xrange(sys.maxint-4,sys.maxint+1): print i
 ...
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 OverflowError: long int too large to convert to int
 >>> for i in xrange(sys.maxint-4,sys.maxint): print i
 ...
 2147483643
 2147483644
 2147483645
 2147483646
 >>> print sys.maxint
 2147483647
</aside>

This could also allow [2:5] or [1:5:2] etc.

For an anonynous slice of integers, it might be reasonable
to interpret negative numbers in the slice as legitimate
indices backwards from zero. E.g., i in [-2:5:2] would be
mean "i in [-2,0,2,4]", not effectively "i in []".

Regards,
Bengt Richter




More information about the Python-list mailing list