Without arguments, returns the list of names in the current local symbol table. With an argument, attempts to return a list of valid attributes 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. If the object is a module object, the list contains the names of the module’s attributes. If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases. Otherwise, the list contains the object’s attribute names (including methods and properties), the names of its class’s attributes, and recursively of the attributes of its class’s base classes. The resulting list is sorted alphabetically. For example:
>>> import struct >>> dir() ['__builtins__', '__doc__', '__name__', 'struct'] >>> dir(struct) ['__doc__', '__name__', 'calcsize', 'error', 'pack', 'unpack']
Note: Because dir is supplied primarily as a convenience for use at an interactive prompt, it tries to return an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases.