python - Why should classes with __get__ or __set__ know who uses them? -
I've just read it and it has been unknowingly felt that depending on who's class behavior it uses Could. >
__ set __ (self, example, value) -
go __ (self, example, owner) Do it the same way. They get in the example of the class that uses them. What is the reason for this design decision? How is this used?
Update: I think about the descriptors in general form. Classes that use them as member types can easily be manipulated with the descriptors' side effects. Here's an example of what I mean, why does Python supprt?
class age (object): def __init __ (value): self.value = value def __get __ (self, example, owener): instance.name = 'manipulation you received' return self .value class person (object): age = age (42) name = 'peter' peter = person () print (peter name, 'is', peter .g)
__ go __ and __ set __ about someone who calls them Do not get information. 3 Logic is the narrator object, the object being used, and the type of object. I think the best way to clean it is with an example, so here's one:
class squares: def descriptor (self): return foo_instance = Foo () method_object = foo_instance.descriptor Work Descriptions When you use the method of the object, apply the method object method and __ get __ The caller is created by finding the function. Here method_object = foo_instance.descriptor call descriptor .__ get __ (foo_instance, Foo) to create Method_object . The __ go __ method does not receive any information about the caller, only necessary information for attribution access to do its job.
Comments
Post a Comment