If you are running your code on a *nix machine, you can use the PureWindowsPath class:

>>> from pathlib import PureWindowsPath, PurePosixPath
>>> path = PureWindowsPath('C:\\Users\\foo\\bar')

>>> path.parts
('c:\\', 'Users', 'foo', 'bar')

>>> PurePosixPath('/usr', *path.parts[2:])
PurePosixPath('/usr/foo/bar')

You can apply the string replace method to every line in a text file as follows:

with open("input.csv", "r") as f_in:
    with open("output.csv", "w") as f_out:
        for line in f_in:
            new_line = line.replace(...)  # magic goes here
            f_out.write("{}\n".format(new_line))
Answer from Selcuk on Stack Overflow
🌐
Python
docs.python.org › 3 › library › os.path.html
os.path — Common pathname manipulations
Source code: Lib/genericpath.py, ... (for Windows). This module implements some useful functions on pathnames. To read or write files see open(), and for accessing the filesystem see the os module. The path parameters can be passed as strings, or bytes, or any object implementing the os.PathLike protocol. Unlike a Unix shell, Python ...
Discussions

Windows path to Python path
I wonder is there a better solution on the issue to convert windows path to python path? Yes; simply use pathlib. from pathlib import Path win_path = r"" path_universal = Path(win_path) print("Your Python Path: ", path_universal) The more you use it, the more you regret not knowing about it earlier. It's an awesome piece of kit in the standard library, probably my favourite. More on reddit.com
🌐 r/learnpython
4
2
February 2, 2022
Python - handling windows path with '\' characters
Hi, I’ve been struggling with windows path for a while because of Python regex. When I need my user to input a path variable in a tool, if they give a classical windows path Python will convert ‘’ because of regex. os.path.normpath don’t seem to work. path = 'L:\sandbox\20_lookdev\... More on tech-artists.org
🌐 tech-artists.org
0
0
December 9, 2019
How to convert Windows path to WSL path?
WSL has a wslpath utility: $ wslpath wslpath: Invalid argument Usage: -a force result to absolute path format -u translate from a Windows path to a WSL path (default) -w translate from a WSL path to a Windows path -m translate from a WSL path to a Windows path, with '/' instead of '\' EX: wslpath 'c:\users' More on reddit.com
🌐 r/bashonubuntuonwindows
6
19
July 7, 2020
Python 3 Quick Tip: The easy way to deal with file paths on Windows, Mac and Linux
... or just use forward slashes on Windows too. Windows has supported them for I don't know how long already, provided your filesystem is NTFS I think. More on reddit.com
🌐 r/Python
64
350
January 31, 2018
🌐
Medium
medium.com › @ageitgey › python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f
Python 3 Quick Tip: The easy way to deal with file paths on Windows, Mac and Linux | by Adam Geitgey | Medium
January 31, 2018 - And if that’s all pathlib did, it would be a nice addition to Python — but it does a lot more! For example, we can read the contents of a text file without having to mess with opening and closing the file: Pro-tip: The previous examples were buggy because the opened file was never closed. This syntax avoids that bug entirely. In fact, pathlib makes most standard file operations quick and easy: You can even use pathlib to explicitly convert a Unix path into a Windows-formatted path:
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
February 23, 2026 - Currently only Windows supports junctions. Added in version 3.12. ... Return True if the path is a mount point: a point in a file system where a different file system has been mounted. On POSIX, the function checks whether path’s parent, path/.., is on a different device than path, or whether path/.. and path point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants.
🌐
Python
python-list.python.narkive.com › WPytiwa0 › convert-between-windows-style-paths-and-posix-style-paths
Convert between Windows style paths and POSIX style paths
I have modules that do this in Windows & Cygwin Python, if you (meaning the OP) are interested. Another way is to access the registry and try to duplicate Cygwin's logic. I tried this but gave up on it--life's too short for that. Or you try to adapt the Cygwin C code. Or try to access the functions in cygwin.dll. Whatever. On an NT system without Cygwin, or on a Unix system, then there is no obvious mapping and (as far I can see) no need for one. Why do you want to use one style of path in your config files?
🌐
Reddit
reddit.com › r/learnpython › windows path to python path
r/learnpython on Reddit: Windows path to Python path
February 2, 2022 -

I have been searching the web for a solution without a result.
I made this small script that can be used. Feel free to use it.
I wonder is there a better solution on the issue to convert windows path to python path?

"""
A path, in Windows "C:\Folder" . in Python it is "C:/Folder".
In Python the "\" character can get interpreted as the ESCAPE character.
When an 'r' or 'R' prefix is present, a character following a backslash is
included in the string without change, and all backslashes are left in the string.
"""
def main():
# - YOUR INPUT - IMPORTANT: keep the r in front of path string here.
win_path = r"<TYPE YOUR PATH HERE>"
# Call function to convert from windows to Python path.
path_py = py_path(win_path)
print("Your Python Path: ", path_py)

def py_path(win_path):
python_path = "" # The result of this script.
# Convert to ASCII list
ascii_values_list = []
for character in win_path:
ascii_values_list.append(ord(character))
# Replace all ASCII values for "\" (=92) with value for "/" (=47).
for i in range(0, len(ascii_values_list)):
if ascii_values_list[i] == 92:
ascii_values_list[i] = 47
path_py = "" # Convert ASCII list to string
for val in ascii_values_list:
path_py = path_py + chr(val)

if path_py[-1] != "/": # Add "/" at end of path if needed.
path_py = path_py + "/"
return path_py

if __name__ == "__main__":
main() # Script goes there.

# EOF

🌐
Tech-Artists.Org
tech-artists.org › t › python-handling-windows-path-with-characters › 12045
Python - handling windows path with '\' characters - Tech-Artists.Org
December 9, 2019 - Hi, I’ve been struggling with windows path for a while because of Python regex. When I need my user to input a path variable in a tool, if they give a classical windows path Python will convert ‘’ because of regex. os.…
Find elsewhere
🌐
Pythondex
pythondex.com › convert-windows-path-to-linux-in-python
Convert Windows Path To Linux In Python - Pythondex
January 31, 2024 - As you can see it just 3 lines of code because we used pathlib module to convert windows path to linux, After running this program you will see it printing the path in linux format like below
🌐
Bytes
bytes.com › home › forum › topic › python
Convert between Windows style paths and POSIX style paths - Post.Byes
On an NT system without Cygwin, or on a Unix system, then there is no obvious mapping and (as far I can see) no need for one. Why do you want to use one style of path in your config files? Surely it would be better to use paths that are appropriate for the system, then process them with Python's os module. -- Mark Hadfield "Ka puwaha te tai nei, Hoea tatou" m.hadfield@niwa .co.nz National Institute for Water and Atmospheric Research (NIWA) ... Re: Convert between Windows style paths and POSIX style paths On Thu, 2003-07-10 at 13:44, Noah wrote:[color=blue] > Does anyone have a function to convert back and forth between > NT style paths and POSIX style?
🌐
Python
docs.python.org › id › 3.13 › library › os.path.html
os.path --- Common pathname manipulations — Dokumentasi Python 3.13.12
Source code: Lib/genericpath.py, Lib/posixpath.py (for POSIX) and Lib/ntpath.py (for Windows). This module implements some useful functions on pathnames. To read or write files see open(), and for accessing the filesystem see the os module. The path parameters can be passed as strings, or bytes, or any object implementing the os.PathLike protocol. Unlike a Unix shell, Python does not do any automatic path expansions.
🌐
Cygwin
cygwin.com › cygwin-ug-net › cygpath.html
cygpath
Output type options: -d, --dos ... 'unix', or 'windows' Path conversion options: -a, --absolute output absolute path -l, --long-name print Windows long form of NAMEs (with -w, -m only, don't mix with -r and -s) -r, --root-local print Windows path with root-local path prefix (\\?\, with -w only) -p, --path NAME is a PATH list (i.e., '/bin:/usr/bin') -U, --proc-cygdrive Emit /proc/cygdrive path instead of cygdrive prefix when converting Windows path ...
🌐
Zditect
zditect.com › blog › 2641391.html
Redirecting...
We cannot provide a description for this page right now
🌐
b.telligent
btelligent.com › en › blog › best-practice-working-with-paths-in-python-part-1-2
Best Practice: Working With Paths In Python (Part 1)
February 12, 2019 - Simply avoid the Windows separator and instead write the path using Linux separators only:‍ · path_dir: str = "C:/Users/sselt/Documents/blog_demo" The interpreter then recognizes the correct path, believing it were a Linux system to start with.
🌐
GeeksforGeeks
geeksforgeeks.org › os-path-module-python
OS Path module in Python - GeeksforGeeks
January 23, 2024 - Python · # isfile function import os out = os.path.isfile("C:\\Users\foo.csv") print(out) Output: True · os.path.normcase(path) function normalizes the case of the pathname specified. In Unix and Mac OS X system it returns the pathname as it is . But in Windows it converts the path to lowercase and forward slashes to backslashes.
🌐
Lerner
blog.lerner.co.il › avoiding-windows-backslash-problems-with-pythons-raw-strings
Client Challenge
August 24, 2018 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
AstroDeck
xspdf.com › resolution › 50935731.html
xspdf — PDF Generation & Processing API for Developers | xspdf
Powerful PDF API for developers. Generate, convert, merge, split, compress, protect and extract PDFs programmatically. RESTful API with simple integration.