[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reasoning of calling a method on class object instead of class instance object

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.