Alternative constructors naming convention
Steven Bethard
steven.bethard at gmail.com
Wed Oct 11 14:44:35 EDT 2006
Will McGugan wrote:
> Is there a naming convention regarding alternative constructors? ie
> static methods where __new__ is called explicity.
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(...)
And FWIW, I use lower_with_underscores for alternate constructors, not
CamelCase.
STeVe
More information about the Python-list
mailing list