Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pprint
- pprint.pprint(globals())
- pprint.pprint(locals())
- def dump(obj):
- '''return a printable representation of an object for debugging'''
- newobj=obj
- if '__dict__' in dir(obj):
- newobj=obj.__dict__
- if ' object at ' in str(obj) and not newobj.has_key('__type__'):
- newobj['__type__']=str(obj)
- for attr in newobj:
- newobj[attr]=dump(newobj[attr])
- return newobj
- class stdClass(object): pass
- obj=stdClass()
- obj.int=1
- obj.tup=(1,2,3,4)
- obj.dict={'a':1,'b':2, 'c':3, 'more':{'z':26,'y':25}}
- obj.list=[1,2,3,'a','b','c',[1,2,3,4]]
- obj.subObj=stdClass()
- obj.subObj.value='foobar'
- from pprint import pprint
- pprint(dump(obj))
- {'__type__': '<__main__.stdClass object at 0x2b126000b890>',
- 'dict': {'a': 1, 'c': 3, 'b': 2, 'more': {'y': 25, 'z': 26}},
- 'int': 1,
- 'list': [1, 2, 3, 'a', 'b', 'c', [1, 2, 3, 4]],
- 'subObj': {'__type__': '<__main__.stdClass object at 0x2b126000b8d0>',
- 'value': 'foobar'},
- 'tup': (1, 2, 3, 4)}
- class Printer:
- def __init__ (self, PrintableClass):
- for name in dir(PrintableClass):
- value = getattr(PrintableClass,name)
- if '_' not in str(name).join(str(value)):
- print ' .%s: %r' % (name, value)
- Printer(MyClass)
Add Comment
Please, Sign In to add comment