Last active
December 21, 2015 14:28
-
-
Save calvingiles/6319368 to your computer and use it in GitHub Desktop.
Slicer Class - grab an instance of SlicerClass and slice it. Pass this anonymously as an argument to get natural slices as arguments instead of using start, stop, step arguments. Works with arbitrarily complex slice arguments as they are just passed through. Usage: foo(slice_arg=slicer[2:7]) or foo(slice_arg=slicer[:2,...,3:4:-0.5]) or even foo(…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlicerClass(object): | |
''' | |
slicerClass allows the creation of a slicer object. | |
A slicer, when indexed with square brackets, will return a slice object. | |
This allows a slice to be created and neatly passed as an argument. | |
''' | |
def __getitem__(self,val): | |
return val | |
def __len__ (self): | |
return 0 | |
slicer = SlicerClass() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could be worthwhile extending this to allow exclusion slices and lists to be used as well as inclusion.