dir() question

Brian Quinlan brian at sweetapp.com
Wed Jan 9 17:31:19 EST 2002


The current documentation for dir states:

"""Without arguments, return the list of names in the current local
symbol table. With an argument, attempts to return a list of valid
attribute for that object. This information is gleaned from the object's
__dict__ attribute, if defined, and from the class or type object. The
list is not necessarily complete. For example, for classes, attributes
defined in base classes are not included, and for class instances,
methods are not included"""

This appears to not be the case:

>>> class A:
...     def a():
...             pass
...
>>> dir(A())
['__doc__', '__module__', 'a']
>>> dir(A)
['__doc__', '__module__', 'a']

Notice how methods ARE included in class instances. Anyone know which is
correct, the documentation or the implementation?

(Also, for classes, base class attributes ARE included)

Cheers,
Brian





More information about the Python-list mailing list