Returning an element from a C struct

Armin Rigo arigo at ulb.ac.be
Tue Mar 19 13:02:34 EST 2002


> How about
>
>     def __getattr__(self,name):
>         try:
>             return self.__dict__[name]
>         except KeyError:
>             return getattr(self.ptr, name)

It even looks like the first 'return' is not needed. If the attribute is
found in the instance then __getattr__() is not called at all.

Armin





More information about the Python-list mailing list