Static Typing in Python
Peter Maas
fpetermaas at netscape.net
Fri Mar 12 08:25:45 EST 2004
Peter Maas schrieb:
> class doesTypeChecking:
> def __init__(self):
> aString = ""
> aFloat = 0.0
sorry, I was too hasty. Here is the tested code:
class doesTypeChecking:
def __init__(self):
self.__dict__["aString"] = ""
self.__dict__["aFloat"] = 0.0
def __setattr__(self, attr, value):
if type(self.__dict__[attr]) != type(value):
raise ValueError, "Type mismatch for attribute %s\n" % attr
Mit freundlichen Gruessen,
Peter Maas
--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------
More information about the Python-list
mailing list