fork(1) download
  1. import json
  2. from collections import namedtuple
  3.  
  4.  
  5. Emp = namedtuple('Emp', 'name age')
  6. Emp.tojson = json.dumps(Emp._asdict())
  7. a = Emp('Luc', 10)
  8.  
  9. print(a.tojson())
Runtime error #stdin #stdout #stderr 0.04s 9544KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 6, in <module>
TypeError: _asdict() missing 1 required positional argument: 'self'