classmethod & staticmethod
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Tue Jul 24 06:57:54 EDT 2007
james_027 a écrit :
> hi,
>
>> The 'real' use is (are) the one(s) you'll find. FWIW, I use
>> staticmethods for helper functions that don't need access to the class
>> or instance but are too specific to a class to be of any use as plain
>> functions. Which is not a very frequent case. Classmethods are more
>> usefull - mostly as alternate constructors or utility methods for an
>> alternate constructor, but there are other possible uses (sorry, I have
>> no concrete example at hand).
>
> You mean like the example from Marc
Marc's example is typically an alternate constructor. This is indeed one
of the most obvious use case of classmethod, but what I meant is that
there are others cases where classmethods can help.
More information about the Python-list
mailing list