+ 3
python static class members
Hi guys, why does a static class member take additional arguements not?
2 Respostas
+ 2
In static method the class is treated as the object, thus cls parameter is required.
+ 2
If you want to manipulate an instance, you take a regular method.
Then the first arg will be the instance (so you can manipulate it).
If you want to manipulate the class itself, you use classmethod.
Again there's a forced first argument, only that this time it's the class (so you can manipulate it), not the instance.
Or you want to access neither the class nor the instance.
Then you use staticmethod.
This time, there's no predefined argument at all, it's just like a regular function, only that it's in a class.
You choose depending on what you want to do.