properties access by name

Rob Williscroft rtw at freenet.co.uk
Fri Oct 17 13:43:25 EDT 2008


=?KOI8-R?B?7cnU0Q==?= wrote in news:f1a77a69-2997-4f53-9a46-
f8bd90d8a67a at m3g2000hsc.googlegroups.com in comp.lang.python:

> 
> 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')

Ther is a builtin `setattr` to do this:

#http://www.python.org/doc/2.5.2/lib/built-in-funcs.html

setattr( f, "title", "bbb" )

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list