On 8/17/05, Timothy Fitz <[EMAIL PROTECTED]> wrote: > On 8/16/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > -0 The behavior of dir() already a bit magical. Python is much simpler > > to comprehend if we have direct relationships like dir() and vars() > > corresponding as closely as possible to the object's dictionary. If > > someone injects non-strings into an attribute dictionary, why should > > dir() hide that fact? > > Indeed, there seem to be two camps, those who want dir to reflect __dict__ > and those who want dir to reflect attributes of an object. It seems to > me that those who want dir to reflect __dict__ should just use > __dict__ in the first place.
Right. > However, in the case of dir handling non-strings, should dir handle > non-valid identifiers as well, that is to say that while > foo.__dict__[2] = ... is an obvious case what about foo.__dict__["1"] > ? See below. > Right now the documentation says that it returns "attributes", and I > would not consider non-strings to be attributes, so either the > documentation or the implementation should rectify this disagreement. I think that dir() should hide non-strings; these aren't attributes if you believe the definition that an attribute name is something acceptable to getattr() or setattr(). Following this definition, the string "1" is a valid attribute name (even though it's not a valid identifier), but the number 1 is not. Try it. :-) -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com