I have already looked a various relevant questions (
__get__() ) here and I couldnt find specific answers. I understand that the class below is trying to create a method on the fly ( possibly we get to this class from a
__getattr__() method which fails to find an attribute ) and return the method to the caller. I have commented right above the lines of code I need understanding with.
class MethodGen(object): def __getattr__(self, name): method = self.method_gen(name) if method: return self.method_gen(name) def method_gen(self, name): def method(*args, **kwargs): print("Creating a method here") # Below are the two lines of code I need help understanding with method.__name__ = name setattr(self, name, method.__get__(self)) return method
If I am not wrong, the
method() function's attribute
__name__ has been set, but in
setattr() function, the attribute of the class
name is set to what ?