Context dependent method in Python - what am I doing wrong?
问题 I would like to create a class whose f method depends on the "mode" the object of the class has been created. The code below doesn't work but hope it gets you an idea of what I am trying to do. My idea is to have a dictionary in which I define the settings for each mode (in this case the function or method to assign to self.f, so that rather than using many if elif statements in the init function I just assign the correct values using the dictionary. class A(object): _methods_dict={ 'a':A.f1,