函数来规范字符串文件路径

2024-06-28 05:52:29 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有一个Python函数可以规范化字符串文件路径或比较字符串文件路径?在

也就是像下面这样的函数(我自己编的):

norm_path = os.normalise("C:\\abc/def/hij\\")
print(norm_path) # c:\abc\def\hij

# I'm looking for a function that converts all "/" to "\\", converts to lowercase
# and removes trailing "\\" or "/" chars so I can compare strings

在我写我自己的函数之前,我想看看是否已经有一个函数可以做到这一点,所以我不会重新发明轮子。在


Tags: 文件topath函数字符串路径normos