overloading constructor in python?
Paddy
paddy3118 at netscape.net
Mon Apr 3 17:09:37 EDT 2006
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
C2 can be initialised with any one, two, three, or zero arguments;
those not given would take the default values shown to the right of the
equals sign above.
- Cheers, Paddy.
--
Signs of spring here in the west-country.
More information about the Python-list
mailing list