This is very simple to do, just import Path
and PureWindowsPath
from pathlib
and then do the following:
# to-windows-path.py
from pathlib import Path, PureWindowsPath
import os
import sys
if __name__ == '__main__':
args = sys.argv[1:]
args_length = len(args)
if args_length != 1:
sys.exit(f"Expected exactly one argument but got {args_length}.")
path = Path(args[0])
pure_windows_path = PureWindowsPath(path)
sys.stdout.write(pure_windows_path.__str__())
Example:
$ python to-windows-path.py path/to/the/file.txt
path\to\the\file.txt