Can I run an operation on an object's attribute when reading?

Phillip B Oldham phillip.oldham at gmail.com
Mon Jan 19 07:04:23 EST 2009


Is it possible to automatically run an operation on a object's
attribute when reading? For instance, if I have the following:

class Item(object):
  tags = ['default','item']

item = Item()

desc = item.tags

When I'm reading the item.tags, I'd like to automagically have the
value converted to a string, eg: "default item". I know I could write
a getter to do this for me, but I'd like to avoid that if possible on
this occasion.

Any help would be great! Thanks.



More information about the Python-list mailing list