Python2.2 doesn't give members of a list

Paul Boddie paul at
Fri Aug 10 11:30:03 CEST 2001

Guido van Rossum <guido at> wrote in message news:<cpsnf090x8.fsf at>...
> Hm.  How about making dir() incompatible in the other direction, and
> letting it return a sorted list of *all* attributes (that one can
> reasonably deduce)?


> >>> print dir([])
>  ['__add__', '__class__', '__contains__', '__delitem__', '__eq__', '__ge__', '__getattr__', '__getitem__', '__getslice__', '__gt__', '__iadd__', '__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__repr__', '__rmul__', '__setitem__', '__setslice__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
> >>>
> Note that print dir(list) would print the same.  Just an idea...

It looks great to me! Of course, as we all know, there's no real way
of discovering "dynamic" attributes implemented using __getattr__ and
__setattr__, but then after doing some work with them, I came round to
the conclusion that those special methods can quickly lead to the
"slip road onto the motorway of obfuscation" [1]. ;-)

One might argue that people could "roll their own" dir if they really
wanted something like this, but your code looks so nice and useful, it
really does merit being part of standard Python or at least part of a
standard module. If you don't want to "corrupt" dir's existing or
proposed meaning, I suppose you could call it something else: xdir


[1] In U.S. English, I suppose you'd say "on ramp onto the highway of
obfuscation". ;-)

More information about the Python-list mailing list