Python2.2 doesn't give members of a list

Paul Boddie paul at
Thu Aug 9 17:58:32 CEST 2001

"Tim Peters" < at> wrote in message news:<mailman.997328534.2490.python-list at>...
> The new scheme is better because more consistent and predictable, but the
> change in dir(builtin_object) is starting to look like it *may* be a bad
> incompatibility with 2.1.  Much as I hate doing it, for this reason I'm
> going to look into hacking inconsistent surprises back into dir().
> although-nothing-can-make-everyone-happy-ly y'rs  - tim

Absolutely not! I was initially surprised that dir(object) didn't give
the methods as well as the attributes, and disappointed that
dir(object.__class__) doesn't state the methods available on that
object. For example:

  class A:
    def a(self):

  class B(A):

b = B()
dir(b.__class__) # doesn't mention method "a" at all

Obviously, there are good reasons for this. Technically, method "a"
isn't a method belonging to class "B" at all, but then one might
expect dir(b) to involve this kind of inferencing. If dir had to
report the methods available on an object, though, it would need to
visit all the base classes and work out what is visible. Instead, that
is left up to the programmer, unless he/she decides upon using the new
introspection module(s).

Perhaps there should be a well-known and widely published way of doing
this kind of thing, but dir is a well-known function. It's a shame
about dir([])...


More information about the Python-list mailing list