Sorting attributes by catagory

Ron Adam rrr at ronadam.com
Wed May 9 11:32:05 EDT 2007


This is for a new version of pydoc if I can get the class attributes sorted 
out.  The module level attributes aren't too difficult to categorize.

(I might be just too tired to see the obvious.)

The original pydoc did this a somewhat round about way, so I would like to 
find a more direct method if possible.


Where dir(obj) is used to get all attributes of a module or class.  And 
they are then sorted into categories depending on what they are.

(In order of precedence.)

For modules:

     - imported_items             (defined in another module,
                                     or is another module)
     - classes
     - functions
     - other_objects              (everything else)


For classes:

     - from_else_where            (object created someplace else)
     - inherited_attributes       (from parents classes or type)
     - static_methods_here
     - class_methods_here
     - other_methods
     - properties
     - getset_descriptors
     - other_descriptors
     - other_attributes           (everything else)


A single function that accepts an object and can return one of the above 
(or equivalent) strings would be ideal.  Finer grained categorizing is ok 
as long as they don't overlap more than one group.

It seems I can get some of these fairly easy with the inspect module, but 
others I need to test in multiple ways.

Any ideas?


Cheers,
    Ron








More information about the Python-list mailing list