osdir.com


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

Question about the @staticmethod decorator


On 3/17/2019 2:15 PM, Arup Rakshit wrote:
> I am reading a book where the author says that:
> 
> In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality ? so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes.
> 
> I didn?t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions?

The addition of @staticmethod was unnecessary in that it did not enable 
any new functionality.  I think beginners should just ignore it.

-- 
Terry Jan Reedy