Creating slice notation from string

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Sep 3 02:16:08 CEST 2009


On Wed, 02 Sep 2009 16:41:34 -0700, Bob van der Poel wrote:

> But, translating 1, 2 or 3 ints into a valid splice isn't quit that
> easy? I could figure each value, and convert them to either int or None
> (key is the None! From my previous try '' doesn't work!)
> 
> But, I still need three possible lines:
> 
>  if len(i) == 1:
>     x=x[i(0)]
>   else if len(i) == 2:
>     x=x[i(0):i(1)]
>    ....

items = [int(n) for n in slice_string.split(":")]
slice(*items)



-- 
Steven



More information about the Python-list mailing list