Skip to content

Instantly share code, notes, and snippets.

@Gatsby-Lee
Last active September 29, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gatsby-Lee/556e60b186ea985afc57b142858a2687 to your computer and use it in GitHub Desktop.
Save Gatsby-Lee/556e60b186ea985afc57b142858a2687 to your computer and use it in GitHub Desktop.
>>> import collections
>>> import json
>>> d = collections.namedtuple("A", "a b c")
>>> d(a=1,b=2,c=3)
A(a=1, b=2, c=3)
>>> f = d(a=1,b=2,c=3)
>>> f
A(a=1, b=2, c=3)
>>> f._asdict()
OrderedDict([('a', 1), ('b', 2), ('c', 3)])
>>> json.dumps(f._asdict())
'{"a": 1, "b": 2, "c": 3}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment