J
jm.suresh
I have a class for rectangle and it has two points in its __slots__ .
However, we can derive a number of properties like width, height,
centerPoint etc from these two points. Now, I want to be able to set
and get these properties directly from the instances. I can either def
__setattr__ , __getattr__ or I can define function for each property
like setWidth(), setHeight() . Which one would be faster? I would
prefer doing through __setattr__, __getattr__ because it makes the code
more readable.
However, speed is a concern I would have to do these operations in few
thousand iterations for about 50-100 rectangles.
However, we can derive a number of properties like width, height,
centerPoint etc from these two points. Now, I want to be able to set
and get these properties directly from the instances. I can either def
__setattr__ , __getattr__ or I can define function for each property
like setWidth(), setHeight() . Which one would be faster? I would
prefer doing through __setattr__, __getattr__ because it makes the code
more readable.
However, speed is a concern I would have to do these operations in few
thousand iterations for about 50-100 rectangles.