I am looking more deeply into the subject of decorators for a bit (So
I can thoroughly digest Steve's information in the thread "basic
decorator question".) and have been first looking at static and class
methods. As a start, I have tried the following:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
py3: class MyClass:
... def my_method():
... print('This is my_method in MyClass!')
py3: class MyOtherClass:
... def my_other_method():
... print('This is my_other_method in MyOtherClass!')
This is my_method in MyClass!
This is my_other_method in MyOtherClass!
I see no difference in result, whether I use the @staticmethod decorator or not.
In "Python Pocket Reference, 5th ed." by Mark Lutz, on page 151 under
the entry "staticmethod(function)" the author states, "... Use the
@staticmethod functiion decorator in version 2.4 and later ... In
Python 3.X only, this built-in is not required for simple functions in
classes called only through class objects (and never through instance
objects)." So what I am understanding is that I only need use the
@staticmethod decorator if I am using Python versions 2.4 through 2.7
(new-style classes). Is my understanding correct?
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options: