Skip to content

Instantly share code, notes, and snippets.

@fndari
Created January 29, 2018 14:45
Show Gist options
  • Save fndari/ee081cb534abdf382540f4c491c61dac to your computer and use it in GitHub Desktop.
Save fndari/ee081cb534abdf382540f4c491c61dac to your computer and use it in GitHub Desktop.
Monkeypatching `rootpy.BaseFunction.__getitem__()`
# from rootpy import *
from rootpy.plotting.func import BaseFunction
def getitem_patched(self, value):
# using `str` instead of `basestring` with py3
# use six.string_types for py2 compatibility
if isinstance(value, str):
idx = self.GetParNumber(value)
elif isinstance(value, int):
idx = value
else:
raise ValueError('Function index must be a integer or a string')
return BaseFunction.ParProxy(self, idx)
BaseFunction.__getitem__ = getitem_patched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment