constructor overwrite

Mug exallion.long at gmail.com
Mon Feb 15 15:31:39 CET 2010


hi ,i had a problem on constructor overwrite:
i have something like:

class obj:
def __init__(self, x=100, y=None):
    if y is None:
          self.x=x
    else:
          self.y=y
so i can call :
objet = obj()  # x=100 y=None
or
objet = obj(40) # x= 40 y=None

but if i do :
objet = obj('not cool') #x='not cool' y=None
since x is not typed .

i am waiting for a result:
objet = obj('not cool') #x=100 y='not cool'
as they do in C++ or java.
is there a way to do it?
thanks



More information about the Python-list mailing list