data strucutures in python
Matthew Banham
matb at photond.com
Thu Sep 21 05:58:01 EDT 2000
Brilliant! Exactly what I want. Cheers!
>
> > class WithProperties:
> > def __getattr__(self,name):
> > if name.startswith('get'):
> > # don't recurse endlessly!
> > raise AttributeError(name)
> > return getattr(self,'get'+name)()
> >
> > def __setattr__(self,name,value):
> > try:
> > setfun = getattr(self,'set'+name)
> > except AttributeError:
> > self.__dict__[name] = value
> > return
> > setfun(value)
> >
> >
> > class C(WithProperties):
> > def setspam(self,value): print 'setting spam to %s' % (value,)
> > def getspam(self): print 'got da spam'
> >
> > c.spam=3
> > --> setting spam to 3
> > c.spam
> > --> got da spam
> >
> > --Jeff (jpet at eskimo.com)
> >
> >
> >
> > --
> > http://www.python.org/mailman/listinfo/python-list
>
> _______________________________________________
> wxPython-users mailing list
> wxPython-users at lists.sourceforge.net
> http://lists.sourceforge.net/mailman/listinfo/wxpython-users
More information about the Python-list
mailing list