Created
September 10, 2010 20:11
-
-
Save mccutchen/574291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Answering this question: | |
# http://stackoverflow.com/questions/3679306/ | |
>>> import json | |
>>> class Foo(object): | |
... def __init__(self, a, b): | |
... self.a = a | |
... self.b = b | |
... | |
>>> foo = Foo('a string', ['a', 'list', 'of', 'strings']) | |
>>> foo | |
<__main__.Foo object at 0x1006ae190> | |
>>> json.dumps(foo.__dict__) | |
'{"a": "a string", "b": ["a", "list", "of", "strings"]}' | |
>>> json.loads(_) | |
{'a': 'a string', 'b': ['a', 'list', 'of', 'strings']} | |
>>> foo2 = Foo(**_) | |
>>> foo2 | |
<__main__.Foo object at 0x1006ae0d0> | |
>>> foo2.__dict__ | |
{'a': 'a string', 'b': ['a', 'list', 'of', 'strings']} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment