Alternative constructors naming convention

Will McGugan will at willNOmcguganSPAM.com
Thu Oct 12 13:19:37 CEST 2006


Steven Bethard wrote:

> Are you really using staticmethod and calling __new__?  It's often much 
> easier to use classmethod, e.g.::
> 
>     class Color(object):
>         ...
>         @classmethod
>         def from_html(cls, r, g, b):
>             ...
>             # convert r, g, b to normal constructor args
>             ...
>             # call normal constructor
>             return cls(...)
> 

I could use that for some things, but often I can avoid an intermediate 
step by bypassing the class constructor altogether...

> And FWIW, I use lower_with_underscores for alternate constructors, not 
> CamelCase.

Seems to be the consensus. I think I'll stick_to_it!



More information about the Python-list mailing list