What is a classmethod for?

Frank Tobin ftobin at neverending.org
Mon Jun 3 16:34:54 EDT 2002

On Sun, 2 Jun 2002, Dennis Peterson wrote:

> That's nice, but I can't think of a use for it, given that we have
> inheritance and isinstance(). Can anyone enlighten me?

Personally, I like using classmethods as secondary constructors, generally
gones that are able to construct 'from' something.


class HostPortAddress(tuple):
	def from_str(self, s):
		return self(s.split(':', 1))
	from_str = classmethod(from_str)

Frank Tobin			http://www.neverending.org/~ftobin/

More information about the Python-list mailing list