我有一个可以在 windows 和 linux 系统上运行的程序。我使用的一个函数切断了路径的一些根,并给我留下了相对路径。
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, './'))
它在Linux下工作,但在Windows下我得到
不完全转义 \U
windows 路径看起来像C:\Users\...
.
处理这个问题的最佳方法是什么?换成 可以\
吗\\
?