overloading constructor in python?
Alex Martelli
aleaxit at yahoo.com
Mon Apr 3 23:15:22 EDT 2006
Paddy <paddy3118 at netscape.net> wrote:
> I guess in python we use two idioms to cover most of the uses of
> mulltiple constructors:
> 1) Duck typing were for example if you do:
>
> class C1(object):
> def __init__(self, n):
> n = float(n)
>
> n could be an integer, a floating point number,, or a string
> representing a float.
>
> 2) Default values to parameters:
>
> class C2(object):
> def __init__(self, x=None, y=None, s=""):
> pass
... and classmethods. OK, _three_ idioms. Oh, and factory functions.
Among the idioms we use are the following...
Alex
More information about the Python-list
mailing list