Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Python's JSON serializer treats NamedTuples as lists. Not wrong once you understand NamedTuples are tuples, but completely unintuitive.

  In [13]: from collections import namedtuple

  In [14]: import json

  In [15]: nt = namedtuple("Test", ["field1", "field2"])

  In [16]: sample = nt(field1="foo", field2="bar")

  In [17]: json.dumps(sample)
  Out[17]: '["foo", "bar"]'


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: