Попробуйте это:
class RandomResponder(object):
choices = [A, B, C]
@classmethod
def which(cls):
return random.choice(cls.choices)
def __getattr__(self, attr):
return getattr(self.which(), attr)
который () случайным образом выбирает опцию из вариантов и который getattr использует для получения атрибута.
РЕДАКТИРОВАТЬ: на самом деле похоже, что вы хотите что-то еще, как это.
class RandomResponder(object):
choices = [A, B, C]
def __getattr__(self, attr):
# we define a function that actually gets called
# which takes up the first positional argument,
# the rest are left to args and kwargs
def doCall(which, *args, **kwargs):
# get the attribute of the appropriate one, call with passed args
return getattr(self.choices[which], attr)(*args, **kwargs)
return doCall
Это можно написать с помощью лямбды, но я просто оставлю это так, чтобы было понятнее.