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

2019-03-19 Thread Peter Otten
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.ce

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

2019-03-18 Thread Michael Torrie
On 03/18/2019 07:09 PM, Ben Finney wrote: > Arup Rakshit writes: > > Michael Torrie writes: > >> On 03/18/2019 05:55 PM, Ben Finney wrote: If I call `_c_to_f`, `_f_to_c` methods on `self` instead of `RefrigeratedShippingContainer` class object, still it works. >>> >>> That's right, an

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

2019-03-18 Thread Ben Finney
Arup Rakshit writes: Michael Torrie writes: > On 03/18/2019 05:55 PM, Ben Finney wrote: > >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of > >> `RefrigeratedShippingContainer` class object, still it works. > > > > That's right, and is indeed the point of making a static method on

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

2019-03-18 Thread Michael Torrie
On 03/18/2019 05:55 PM, Ben Finney wrote: >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of >> `RefrigeratedShippingContainer` class object, still it works. > > That's right, and is indeed the point of making a static method on a > class. I'm confused. The methods that refer to Refi

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

2019-03-18 Thread Ben Finney
Arup Rakshit writes: > class RefrigeratedShippingContainer(ShippingContainer): > # ... > > @staticmethod > def _c_to_f(celsius): > return celsius * 9/5 + 32 > > @staticmethod > def _f_to_c(fahrenheit): > return (fahrenheit - 32) * 5/9 Both those functions are

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

2019-03-18 Thread Arup Rakshit
Hi, In this piece of code: class RefrigeratedShippingContainer(ShippingContainer): MAX_CELSIUS = 4.0 def __init__(self, owner_code, contents, celsius): super().__init__(owner_code, contents) if celsius > RefrigeratedShippingContainer.MAX_CELSIUS: raise ValueE