如何在列表中转换字符串

时间:2017-11-13 01:15:18

标签: python

# read from file
code = [line.strip() for line in open(file_path)] # file content: "var x = '\n'"

# print(code) now looks like: ["var x = '\\n'"]

# write json to disk
with open('json.cfg', 'w') as file:
      file.write(json.dumps(code))



>> cat json.cfg
>> "var x = '\\n'"

我希望json.cfg内容为:"var x = '\n'"

0 个答案:

没有答案