python - Why aren't all the names in dir(x) valid for attribute access? -


Why a codec changes things into __ dict __ , which is used for use can not be done? For example, in my Plone example, dir (portal) contains index_html , but portal.index_html increases AttributeError. This is also true for the properties of __ class __ for the properties. ZCatalog.Catalog.mybrains dir () Can not be trusted?

Call around the Inspection module, I think they use the object for this reason instead of attribution access .__ dict __ ['x'] and because they do not want to trigger the getattr magic.

I do not know about the plan, so the following is normal.

From dir

If the object is a method called __dir __ () The method will be asked and the list of properties will be returned. This allows objects that custom __getattr __ () or __ getattribute __ () function optimized as dir () Allows to >

Just guessing here, but I can think of two things that can be -

  • __ dir in the object __ () method that gives the characteristics that are not in it

  • (less likely) object is the attribute you ask (I.e. this obj.de dict __ or type (obj) .__ dict __ , but override __getattr __ to return attributeError

Edit : __ Dior __ Only supported in Python 2.6+, however (deprecated) special features __ methods __ and __ member__ can be used for earlier versions.


Comments