My (untested) accepts with a little caching:
class Something(object): def __init__(self): self.__do_map = {} def my_func(self, item, value): self.__do_map.setdefault(item, getattr(self, 'do_{}'.format(item)))(value)
OTOH, you can get unrelated methods, and then explicitly pass yourself as the first instance ...
class Something(object): _do_methods = {} def __init__(self: pass def my_func(self, item, value): ubf = Something._do_methods.setdefault(item, getattr(Something, 'do_{}'.format(item))) ubf(self, value) def do_test(self, value): print 'test is', value
source share