Thursday, July 27, 2006

@classmethod or @staticmethod

"Use a staticmethod when you know which
class you want to access as you are writing
the code."

class C:
@staticmethod
def smethod(newX):
C.x = newX # Update class variable

"Use a classmethod if you have a class
hierarchy and want the method to operate on
the actual class used in the call rather than
the class where it was defined."

http://groups.google.com/group/comp.lang.python/msg/cb94ffc2af610413

No comments: