Read Only attributes, auto properties and getters and setters
dear.jay.logan at gmail.com
Thu Feb 12 11:27:09 EST 2009
On Feb 12, 10:58 am, TechieInsights <GDoerm... at gmail.com> wrote:
> Oh... one other thing that would be really cool is to do this with AOP/
> descriptors! I just haven't been able to get that to work either.
> class MyClass(object):
> def __init__(self, x):
> def get_x(self):
> return self.__x
> def set_x(self, x):
> print 'Hello the setter was called!'
> self.__x = x
> and it's done! I don't think this will work because (maybe I'm wrong)
> but I don't think you can set the metaclass in the descriptor??? If
> this is the case, it is more work to do the AOP and set a metaclass...
> better to just inherit. If it can be done... that would be awesome!
Are your needs not already satisfied by the Python built-in property?
More information about the Python-list