property in Py2.2
Markus Jais
info at mjais.de
Tue Jun 4 17:07:16 EDT 2002
hi
this is an example I am using:
############
class Address(object):
__slots__ = ('firstname', 'lastname', 'street', 'zipcode', '
city', 'country', '_email', 'phone_private',
'phone_work', 'phone_mobile', 'birthday', 'comment')
def __init__(self):
self.firstname = ""
self.lastname = ""
self.street = ""
self.zipcode = ""
self.city = ""
self.country = ""
self._email = ""
self.phone_private = ""
self.phone_work = ""
self.phone_mobile = ""
self.birthday = ""
self.comment = ""
def set_email(self, email):
if re.match(".*@.*\..*", email): # must contain '@' and a '.'
self._email = email
else:
print "wrong" # TODO raise Exceptionm
def get_email(self):
return self._email
email = property(get_email, set_email, None, 'Setting the email adress')
############
markus
Giorgi Lekishvili wrote:
> Hi all!
>
> I wonder if someone finds time to send me a real code of how to use
> properties in Py2.2
>
> I would be much obliged, if you also send me a version of the code for
> Py2.1, with __setattr__ and __getattr__.
>
> Thx,
> Giorgi
>
> PS. Prior to post here, I have read the materials on www.python.org. I
> find them very helpful.
More information about the Python-list
mailing list