2013-04-13 31 views
1

是否有可以規範化字符串文件路徑或比較字符串文件路徑的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 

之前,我寫我自己的功能,我想看看那裏有已經執行此功能,所以我不另起爐竈。

回答

4
>>> import os 
>>> print(os.path.normcase(os.path.normpath("C:\\abc/def/hij\\"))) 
c:\abc\def\hij 
相關問題