How to dump a Python dictionary to JSON when keys are non-trivial objects?

后端 未结 4 1092
深忆病人
深忆病人 2021-02-08 05:54
import datetime, json
x = {\'alpha\': {datetime.date.today(): \'abcde\'}}
print json.dumps(x)

The above code fails with a TypeError since

4条回答
  •  梦谈多话
    2021-02-08 06:22

    you can do x = {'alpha': {datetime.date.today().strftime('%d-%m-%Y'): 'abcde'}}

提交回复
热议问题