No method overloadin I suppose ?
Gerald Klix
gklix at hassler.de
Thu Apr 13 05:39:43 EDT 2000
Thomas SMETS wrote:
> ## Beginning of Python program ...
> class Lister:
> def __init__(self):
> print 'In constructor ...'
> __init__(1)
>
> def __init__(self, lValue):
> print 'In constructor with parameter'
> self.l = lValue
>
> def __repr__(self):
> print '\n******\n\tValue is : ', l, '\n********'
>
> if __name__ == "__main__":
> x = Lister()
> y = Lister (2)
> ## End of python program
>
> Trace of execution is :
> Traceback (innermost last):
> File "Minheritence.py", line 14, in ?
> x = Lister()
> TypeError: not enough arguments; expected 2, got 1
> End of trace ...
>
> I guess I can't do methods overloadin', as shown... WHY is that ? I'm
> wrong ?
>
> Thomas,
>
> --
Yes Thomas, you can't do overloading. The second __init__ method
overides the first one.
But you can do:
def __init__( self, lValue = 1 ):
self.l = lValue
Gerald
More information about the Python-list
mailing list