Reputation: 1822
Is it possible to change the values in a python slice object?
For example, if I have
slice(0,1,None)
How would I, in effect, add 1 to the start and end values and so convert this to:
slice(1,2,None)
Upvotes: 2
Views: 503
Reputation: 95992
Not exactly elegant, but it works:
>>> s1 = slice(0,1,None)
>>> s2 = slice(s1.start + 1, s1.stop + 1, s1.step)
>>> s2
slice(1, 2, None)
>>>
Upvotes: 4