Print a nicely formatted overview of an object. The output lines will be wrapped at maxlen, with lindent of space for names of attributes. A maximum of maxspew characters will be printed for each attribute value. You can hand dumpObj any data type -- a module, class, instance,
(obj, maxlen=77, lindent=24, maxspew=600)
| 3 | print format % (str(key)+':', val) |
| 4 | |
| 5 | def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): |
| 6 | """Print a nicely formatted overview of an object. |
| 7 | |
| 8 | The output lines will be wrapped at maxlen, with lindent of space |
| 9 | for names of attributes. A maximum of maxspew characters will be |
| 10 | printed for each attribute value. |
| 11 | |
| 12 | You can hand dumpObj any data type -- a module, class, instance, |
| 13 | new class. |
| 14 | |
| 15 | Note that in reformatting for compactness the routine trashes any |
| 16 | formatting in the docstrings it prints. |
| 17 | |
| 18 | Example: |
| 19 | >>> class Foo(object): |
| 20 | a = 30 |
| 21 | def bar(self, b): |
| 22 | "A silly method" |
| 23 | return a*b |
| 24 | ... ... ... ... |
| 25 | >>> foo = Foo() |
| 26 | >>> dumpObj(foo) |
| 27 | Instance of class 'Foo' as defined in module __main__ with id 136863308 |
| 28 | Documentation string: None |
| 29 | Built-in Methods: __delattr__, __getattribute__, __hash__, __init__ |
| 30 | __new__, __reduce__, __repr__, __setattr__, |
| 31 | __str__ |
| 32 | Methods: |
| 33 | bar "A silly method" |
| 34 | Attributes: |
| 35 | __dict__ {} |
| 36 | __weakref__ None |
| 37 | a 30 |
| 38 | """ |
| 39 | |
| 40 | import types |
| 41 | |
| 42 | # Formatting parameters. |
| 43 | ltab = 2 # initial tab in front of level 2 text |
| 44 | |
| 45 | # There seem to be a couple of other types; gather templates of them |
| 46 | MethodWrapperType = type(object().__hash__) |
| 47 | |
| 48 | # |
| 49 | # Gather all the attributes of the object |
| 50 | # |
| 51 | objclass = None |
| 52 | objdoc = None |
| 53 | objmodule = '<None defined>' |
| 54 | |
| 55 | methods = [] |
| 56 | builtins = [] |
| 57 | classes = [] |
| 58 | attrs = [] |
| 59 | for slot in dir(obj): |
| 60 | attr = getattr(obj, slot) |
| 61 | if slot == '__class__': |
| 62 | objclass = attr.__name__ |
nothing calls this directly
no test coverage detected