I have a program that should be runnable on windows and linux systems. One function I use cuts off some root of a path and leaves me with the relative path.
import re
from pathlib import Path
def relative_path(absolute_absolute, root_path):
a = str(absolute_absolute)
r = str(root_path)
assert re.search(r, a) is not None, (r, a)
return Path(a.replace(r, './'))
It works under Linux, but under windows I get
incomplete escape \U
The windows path looks like C:\Users\...
.
What is the best way to deal with this? Is it OK to replace \
with \\
?