Read Only attributes, auto properties and getters and setters

TechieInsights GDoermann at
Thu Feb 12 16:58:32 CET 2009

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!


More information about the Python-list mailing list