Possible to slice a string with unpacked tuple?

MRAB google at mrabarnett.plus.com
Sat Jan 24 17:52:19 EST 2009


python at bdurham.com wrote:
>   Is there a way to slice a string with a tuple without unpacking the tuple?
> 
>  >>> myString = "111-222-333-444"
>  >>> myString[ 4: 7 ]
> '222'
> 
> Is there some way I could perform an identical slicing operation with a 
> tuple like ( 4, 7 ) without having to unpack the tuple?
> 
>  >>> myTuple = ( 4, 7 )
> 
> Thanks!
> 
Does myString[myTuple[0] : myTuple[1]] count as unpacking? If it does, 
then how about myString.__getslice__(*myTuple)?



More information about the Python-list mailing list