Thought on PEP 204 and 276
Gustavo Cordova
gcordova at hebmex.com
Mon May 27 16:45:28 EDT 2002
>
> 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 :
>
>
> As for the ideas like allowing '[1, 5:10, 20]', combining the syntax
> with list comprehensions, etc I feel the common policy of KISS (ie
> just do the minimal slice-like notation) is a good principle.
>
> On the issue that it could be confused with slices, consider the
> following...
>
> (1, 2)
>
> Is that a tuple containing the values 1 and 2, or is it the actual
> parameter list for a function call? - you can only tell from the
> context (ie was there a function name, variable containing a lambda or
> whatever to the left). Clearly the slice/range-list dilemma is no more
> confusing than syntax that already exists.
>
> As for being non-obvious, I'd say it's as obvious as using the slice
> notation for slices.
>
> In short, PEP 204 seems intuitive to me while PEP 276 makes me worry.
>
> Am I alone in thinking this?
>
> --
> Steve Horne
> steve at lurking.demon.co.uk
>
just make an Ints module, with an Ints object (or which inserts
into __builtins__ an Ints object, but that's nasty).
-- clip here --
class _Ints:
def __init__(self): pass
def __getitem__(self, range):
if type(range) != SliceType:
raise ValueError("The range must be a slice!")
return xrange(range.start, range.stop, range.step)
Ints = _Ints()
del _Ints
-- clip here --
and VoilĂ , you can obtain integer ranges with simply:
from Ints import Ints
for x in Ints[10:30:2]:
do(x)
neato :-)
-gus
More information about the Python-list
mailing list