Python2.2 doesn't give members of a list

Tim Peters tim.one at home.com
Sat Aug 11 21:56:59 EDT 2001


[Tim]
> 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

[Paul Boddie]
> Absolutely not!

LOL -- "absolutely not" *what*?  It's absolutely not more consistent,
absolutely not more predictable, absolutely not an incompatibility, I
absolutely should not look at hacking backward-compatibility crud back into
dir(), or it's absolutely not the case that nothing can make everyone happy?

> ...
> 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([])...

dir() may be well-known, but what it does isn't.  It was originally added
with dir(module) in mind, and nothing more than that -- just a shorthand for

def dir(x):
    k = x.__dict__.keys()
    k.sort()
    return k

That it did anything for objects that didn't have an explicit __dict__ is
due to layers of special-case hacks added over time, sucking in searches for
__methods__ and __members__ too (which are themselves ill-defined).

I like Guido's idea of having it return more instead of less, though.  In
any case, introspective needs vary too much by context to hope that a single
simple function will make everyone happy -- or even anyone happy all the
time.

and-it-is-a-shame-about-dir([])-otherwise-ly y'rs  - tim





More information about the Python-list mailing list