Skip to content

Instantly share code, notes, and snippets.

@tokibito
Created August 30, 2013 05:38
Show Gist options
  • Save tokibito/6386611 to your computer and use it in GitHub Desktop.
Save tokibito/6386611 to your computer and use it in GitHub Desktop.
pprint and vars
>>> class MyClass(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
... self.foo = {'foo': {'bar': 'hoge'}}
... self.ref = self
...
>>> obj = MyClass(10, 20)
>>> vars(obj)
{'y': 20, 'x': 10, 'foo': {'foo': {'bar': 'hoge'}}, 'ref': <__main__.MyClass object at 0x025E46D0>}
>>> import pprint
>>> pprint.pprint(vars(obj))
{'foo': {'foo': {'bar': 'hoge'}},
'ref': <__main__.MyClass object at 0x025E46D0>,
'x': 10,
'y': 20}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment