Python - dump dict as a json string -
what missing? want dump dictionary json string.
i using python 2.7
with code:
import json fu = {'a':'b'} output = json.dump(fu)
i following error:
traceback (most recent call last): file "/usr/local/lib/python2.7/dist-packages/gevent-1.0b2-py2.7-linux-x86_64.egg/gevent/greenlet.py", line 328, in run result = self._run(*self.args, **self.kwargs) file "/home/ubuntu/workspace/bitmagister-api/mab.py", line 117, in mabloop output = json.dump(fu) typeerror: dump() takes @ least 2 arguments (1 given) <greenlet @ 0x7f4f3d6eec30: mabloop> failed typeerror
use json.dumps
dump str
>>> import json >>> json.dumps({'a':'b'}) '{"a": "b"}'
json.dump
dumps file
Comments
Post a Comment