Read Only attributes, auto properties and getters and setters

josh logan dear.jay.logan at
Thu Feb 12 11:27:09 EST 2009

On Feb 12, 10:58 am, TechieInsights <GDoerm... at> 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.
> Basics...
> @readonly
> class MyClass(object):
>         def __init__(self, x):
>                 self.set_x(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!
> Greg

Are your needs not already satisfied by the Python built-in property?

More information about the Python-list mailing list