KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
While trying to wrap arbitrary objects, I came across a problem with dictionaries and lists. Investigating, I managed to come up with a simple piece of code whose behaviour I simply do not understand. I hope some of you can tell me what is going on: >>> class Cl(object): # simple class that prints (and suppresses) each attribute lookup ... def __getattribute__(self, name): ... print 'Access:', name ... >>> i = Cl() # instance of class >>> i.test # test that __getattribute__ override works Access: test >>> i.__getitem__ # test that it works for special functions, too Access: __getitem__ >>> i['foo'] # but why doesn't this work? Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'Cl' object has no attribute '__getitem__'
Tags (comma-separated)
Save Edits
Cancel