@staticmethod question
Posted: Thu Dec 14, 2017 9:16 am
Hi,
I have the following example class:The reason I'm asking is because I have the global instance anyway in my code, so it makes some kind of sense to use it instead of the class/type itself. How do you view this "issue"? Python doesn't really care as far as results go, but I'm not too sure if using the instance is "pythonic". Thanks!
I have the following example class:
Syntax: Select all
class MyClass(object):
# ... some instance methods ...
@staticmethod
def my_static_method(value):
return value * 5
# Global instance for the class
my_class = MyClass()
# ...
# Since it's a static method, it should be called like this:
fifty = MyClass.my_static_method(10)
# But is it OK to do the following as well?
fifty = my_class.my_static_method(10)