[Tutor] classmethod, staticmethod functions (decorator related)
steve at pearwood.info
Mon Sep 13 13:05:10 CEST 2010
On Mon, 13 Sep 2010 12:29:07 pm Huy Ton That wrote:
> Hm, thanks guys; I just had to verify I was thinking sanely about it.
> I am going to pick up classmethods next. Do any of you have common
> design patterns for the usage. They are just items I haven't
> integrated in my coding, and I want to be certain I'm off on the
> right foot (:
The most common use for classmethods is to implement alternative
constructors. For example, in the Decimal class starting in version 2.7
and 3.1, you have two constructors:
>>> from decimal import Decimal
from_float is a class method.
More information about the Tutor