Metaclass v.s. Property function.
Duncan Booth
duncan.booth at invalid.invalid
Sat Aug 11 12:06:18 EDT 2007
Jens Thiede <jensthiede at gmail.com> wrote:
> I don't like the property function, usable in the new-style classes,
> because having to remember to manage a list of "foo = property(...)"
> assignments just plain sucks, so I wrote a metaclass that does things
> a little differently. Please have a look and tell me whether this is
> useful or impractical. The metaclass is here:
> http://pastebin.com/m5b06b571 and some simple testcode is here:
> http://pastebin.com/m382f2ae9. Notice the first line though.
>
Here's something I posted a while back which lets you use property as a
decorator:
class C(object):
def __init__(self, colour):
self._colour = colour
@property.set
def colour(self, value):
self._colour = value
@property.get
def colour(self):
return self._colour
@property.delete
def colour(self):
self._colour = 'none'
See:
http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/b442d08c9a019a8/8a381be5edc26340
Whether you like that style is of course a matter of personal opinion.
More information about the Python-list
mailing list