I want to be able to use backslashes in string literals, for example: C:\file.txt
I was expecting to be able to escape the backslash with "\\"
, but for some weird reason that produces two backslashes instead of one. Why?
MVCE:
with open("temp.csv", 'w', encoding='utf-8') as f:
d = { "filepath" : "C:\\bahä.txt" }
s = json.dumps(d, ensure_ascii=False)
f.write(s)
Expected behavior: file content should be C:\bahä.txt
Actual behavior: file content is C:\\bahä.txt