Answer the question
In order to leave comments, you need to log in
How to properly wrap file path?
Hey! I ran into a problem, how to wrap
the path to the file so that the backslash does not escape?
I know it's common to add " r " to the beginning of the path, but how do I
write that inside the json file?
Answer the question
In order to leave comments, you need to log in
You need to double the slashes, since they are also required to be escaped in json.
>>> data = {"path": r"C:\Test\123"}
>>> data
{'path': 'C:\\Test\\123'}
>>> print(json.dumps(data))
{"path": "C:\\Test\\123"}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question