Created
January 29, 2018 14:45
-
-
Save fndari/ee081cb534abdf382540f4c491c61dac to your computer and use it in GitHub Desktop.
Monkeypatching `rootpy.BaseFunction.__getitem__()`
This file contains 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
# 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