Read Only attributes, auto properties and getters and setters

TechieInsights GDoermann at gmail.com
Thu Feb 12 11:32:37 EST 2009


On Feb 12, 9:27 am, josh logan <dear.jay.lo... at gmail.com> wrote:
> 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.
> > 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?
>
> http://docs.python.org/dev/3.0/library/functions.html#property

yea... just read the docs... I love reinventing the wheel (sarcasm)...

Thanks for this... I just realized that you can set the fset and fdel
to None... so everything can be done from the metaclass!



More information about the Python-list mailing list