Reasoning of calling a method on class object instead of class instance object
Peter Otten
__peter__ at web.de
Tue Mar 19 05:18:16 EDT 2019
Arup Rakshit wrote:
> In this piece of code:
>
> class RefrigeratedShippingContainer(ShippingContainer):
> @staticmethod
> def _c_to_f(celsius):
> return celsius * 9/5 + 32
> @property
> def fahrenheit(self):
> return RefrigeratedShippingContainer._c_to_f(self.celsius)
> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
> `RefrigeratedShippingContainer` class object, still it works. So what is
> the reason behind of this calling on the class object, instead class
> instance object?
I don't know, but I would prefer self over the class name.
More information about the Python-list
mailing list