how do i create such a thing?

Alex Martelli aleaxit at yahoo.com
Tue Feb 1 05:29:16 EST 2005


Lowell Kirsh <lkirsh at cs.ubc.ca> wrote:

> What might these exceptions be?
> 
> > It's HIGHLY advisable to have your __getattr__ methods raise
> > AttributeError for any requested name that starts and ends with double
> > underscores, possibly with some specific and specifically designed
> > exceptions.

For example, delegation of such requests to some other object:
    def __getattr__(self, name):
        return getattr(self._delegate, name)

In such cases you may decide you do not need to block __specials__,
because you're OK with having self._delegate supply them or be
responsible to raise AttributeError if necessary.


Alex



More information about the Python-list mailing list