函数用于规范化字符串文件路径



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

是一个像下面这样的函数(我编的):

norm_path = os.normalise("C:\abc/def/hij\")
print(norm_path) # c:abcdefhij
# I'm looking for a function that converts all "/" to "\", converts to lowercase
# and removes trailing "\" or "/" chars so I can compare strings

在我写自己的函数之前,我想看看是否已经有这样的函数,这样我就不用重新发明轮子了

>>> import os
>>> print(os.path.normcase(os.path.normpath("C:\abc/def/hij\")))
c:abcdefhij

最新更新