How to dump json without quotes in python

后端 未结 5 2176
孤街浪徒
孤街浪徒 2021-02-14 17:59

Here is how I dump a file

with open(\'es_hosts.json\', \'w\') as fp:
  json.dump(\',\'.join(host_list.keys()), fp)

The results is



        
5条回答
  •  忘掉有多难
    2021-02-14 18:33

    Before doing a string replace, you might want to strip the quotation marks:

    print '"a,b,c"'.strip('"')
    

    Output:

    a,b,c
    

    That's closer to what you want to achieve. Even just removing the first and the last character works: '"a,b,c"'[1:-1].

    But have you looked into this question?

提交回复
热议问题