Skip to content

Instantly share code, notes, and snippets.

@calvingiles
Last active December 21, 2015 14:28
Show Gist options
  • Save calvingiles/6319368 to your computer and use it in GitHub Desktop.
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(…
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()
@calvingiles
Copy link
Author

Could be worthwhile extending this to allow exclusion slices and lists to be used as well as inclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment