How To Deal With Json And Windows Paths In Python?
I'm trying to run a Python package which reads a JSON file (config file) for information. The problem is I need to edit some of the JSON file to included directories. The creator o
Solution 1:
/
is a valid directory separator on Windows, and has been since MS-DOS 2. You can even mix them in the same path, but that looks horrible.
Some applications insist on \
, but you might want to try using /
before making work for yourself.
An important reason for using \
on Windows is where users expect it. The \
has got so ingrained in Windows culture that it unsettles people when they see /
.
Solution 2:
Another way you may try.
Read the desired path variable from your json
file.
And you can replace the path variable string /
to \\
. And hope it will work
# Assuming path variable string as "path"windows_path = path.replace("/","\\")
Post a Comment for "How To Deal With Json And Windows Paths In Python?"