[Tutor] modified dictionary class

Alan Gauld alan.gauld at btinternet.com
Mon Dec 6 14:47:20 CET 2010


"Joel Goldstick" <joel.goldstick at gmail.com> wrote 

>>    def __getattr__(self, attr):
>>        # Fake a __getstate__ method that resturns None
>>        if attr == "__getstate__":
>>            return lambda: None

> why not "return None"?
> 
> 
>>        return self[attr]

Oops, too quick. I neant to add:

But this line seems to return a value so the return values 
of this function seem to be incompatible which is not 
a good design pattern.

If attr is getstate it returns a function object.
Otherwise it returns whatever the dict holds 
- Unless the dict holds functions of course.

Alan G.



More information about the Tutor mailing list