Call method from string
You can do this: getattr(CallMe, variable)() getattr is a builtin method, it returns the value of the named attributed of object. The value in this case is a method object that you can call with ()
You can do this: getattr(CallMe, variable)() getattr is a builtin method, it returns the value of the named attributed of object. The value in this case is a method object that you can call with ()
Basically performSelector allows you to dynamically determine which selector to call a selector on the given object. In other words the selector need not be determined before runtime. Thus even though these are equivalent: [anObject aMethod]; [anObject performSelector:@selector(aMethod)]; The second form allows you to do this: SEL aSelector = findTheAppropriateSelectorForTheCurrentSituation(); [anObject performSelector: aSelector]; before you … Read more
Your guess is correct – you understand how classmethods work. The why is that these methods can be called both on an instance OR on the class (in both cases, the class object will be passed as the first argument): class Dummy(object): @classmethod def some_function(cls,*args,**kwargs): print cls #both of these will have exactly the same … Read more