properties access by name

Митя netimen at gmail.com
Fri Oct 17 12:36:49 EDT 2008


I use rwproperty (http://pypi.python.org/pypi/rwproperty/1.0) and so I
have properties in my class. Also I have a list of names of properties
wich I am to set. How can I access my properties by name in such way
that when I want to set a property, setter will be called, and and
when I want to read it - getter?

I have something like this:

class Film(object):
    def __init__(self, title):
        self.__title = title

    @getproperty
    def title(self):
        return self.__title
    @setproperty
    def title(self, value):
        self.__title = value

properties_to_set = ['title']
f = Film('aaa')

I d want to have sth like:
f(properties_to_set[0]) = 'bbb'

If title was a simple variable I could write:
f.__dict__[properties_to_set[0]] = 'bbb'

now I can write:
f.__dict__['_Film__' + properties_to_set[0]] = 'bbb'

but I want to set my property through the provided setter. How can I
do this?

P.S. Sorry for my english



More information about the Python-list mailing list