synthetic properties

Diez B. Roggisch deets at nospam.web.de
Tue Sep 2 16:29:33 EDT 2008


rowland at river2sea.org schrieb:
> I'm trying to come up with solution for adding synthetic properties to
> python, similar to synthetic properties in Objective-C.
> 
> I'm playing around with doing this in a MetaClass.  I can dynamically
> create the attributes that will back the property, but I'm having
> trouble figuring out how to dynamically generate get/set methods to
> pass to the built-in property() function.

Why on earth do you want to do that? The reason synthesized properties 
exist in ObjC is simply that to expose properties for key-value-coding, 
one needs the getter/setters. But mostly these are boilerplate, so apple 
introduced the @synthesized-annotation.

But in python, you don't need that. You use simple attributes. In the 
very moment you need logic attached, use the builtin property to do so.




Diez



More information about the Python-list mailing list