0
# 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'"

I'd like json.cfg content to be: "var x = '\n'"

Kam
  • 5,878
  • 10
  • 53
  • 97
  • Wait... why is `code[0] == "var x '\\\\n'"`? – Mateen Ulhaq Nov 13 '17 at 01:17
  • I'm not 100% I understand your question but I think you are asking about dynamic variables. https://stackoverflow.com/questions/5036700/how-can-you-dynamically-create-variables-via-a-while-loop – J'e Nov 13 '17 at 01:21

0 Answers0