Possible to slice a string with unpacked tuple?

Terry Reedy tjreedy at udel.edu
Sat Jan 24 20:45:25 EST 2009


Benjamin Peterson wrote:
> MRAB <google <at> mrabarnett.plus.com> writes:
>> Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, 
>> then how about myString.__getslice__(*myTuple)?
> 
> Please don't use special method names directly and especially not
> __getslice__(). It's deprecated and will be removed.

It is gone in 3.0.  In 3.0, at least, and perhaps later 2.x (not sure)
the OP should simply write
    myString[slice(*myTuple)]
which is the semantic equivalent of
    myString[myTuple[0]:myTuple[1]]




More information about the Python-list mailing list