Why would a coder stuff things into __dict__ that can’t be used for attribute access? For example, in my Plone instance, dir(portal) includes index_html, but portal.index_html raises AttributeError. This is also true for the __class__ attribute of Products.ZCatalog.Catalog.mybrains. Is there a good reason why dir() can’t be trusted?
Poking around the inspect module, I see they use object.__dict__['x'] instead of attribute access for this reason and because they do not want to trigger getattr magic.
I don’t know about Plone, so the following is general.
From the docs of
dir:Just guessing here, but I can think of two things that may be happening–
The object has a
__dir__()method that returns attributes that it doesn’t have(less likely) The object has the attribute you’re asking for (i.e. it’s in
obj.__dict__ortype(obj).__dict__, but overrides__getattr__to returnAttributeErrorEDIT:
__dir__is only supported in Python 2.6+, however the (deprecated) special attributes__methods__and__members__can be used instead for earlier versions.