I have a python Class with all methods being static,
class SomeClass:@staticmethoddef somemethod(...):pass@staticmethoddef somemethod2(...):pass@staticmethoddef somemethod3(...):pass
Is it the right way to do so?
I have a python Class with all methods being static,
class SomeClass:@staticmethoddef somemethod(...):pass@staticmethoddef somemethod2(...):pass@staticmethoddef somemethod3(...):pass
Is it the right way to do so?
If all the methods are static, you DON'T need a class.
(Same if you have a class with only an init and 1 method)
class SomeClass:@staticmethoddef somemethod(...):pass@staticmethoddef somemethod2(...):pass@staticmethoddef somemethod3(...):pass
Then you use it mostly like:
from someclass import SomeClass
some_class = SomeClass()
some_class.somemethod()
....
def somemethod(...):passdef somemethod2(...):passdef somemethod3(...):pass
then I use it this way:
import someclass
someclass.somemethod()
...
Isn't this cleaner and simpler?
class SomeClass:foo = 1def __init__(self, bar):self.bar = barself.foo = 2@staticmethoddef somemethod():# no access to self nor cls but can read foo via SomeClass.foo (1)foo = SomeClass.fooSomeClass.someclassmethod()...@classmethoddef someclassmethod(cls, ...):# access to cls, cls.foo (always 1), no access to barfoo = cls.foo...def someinstancemethod(self, ...):# access to self, self.bar, self.foo (2 instead of 1 because of init)foo = self.foobar = self.barself.somemethod()self.someclassmethod()...