What is a classmethod for?
ftobin at neverending.org
Tue Jun 11 05:16:30 CEST 2002
On 10 Jun 2002, Kragen Sitaker wrote:
> That's so you don't have to write this?
> class HostPortAddress(tuple): pass
> def HostPortAddress_from_str(s):
> return HostPortAddress(s.split(':', 1))
Well, it makes sense to throw all the 'knowledge' of how to stringify and
de-stringify a HostPortAddress into one class.
> Are there times when it's more compelling?
Another example would be anytime where you have something that is close to
a staticmethod which is a helper to the instance methods ,but needs some
information that only the class can provide.
Frank Tobin http://www.neverending.org/~ftobin/
More information about the Python-list