os.path.splitext(“文件路徑”) 分離文件名與擴展名;默認返回(fname,fextension)元組,可做分片操,切片操作中方便找到以一些特殊的後綴的文件夾。
example:
import os
path_01='D:/User/wgy/workplace/data/notMNIST_large.tar.gar'
path_02='D:/User/wgy/workplace/data/notMNIST_large'
root_01=os.path.splitext(path_01)
root_02=os.path.splitext(path_02)
print(root_01)print(root_02)
輸出結果
結果:
('D:/User/wgy/workplace/data/notMNIST_large.tar', '.gar')
('D:/User/wgy/workplace/data/notMNIST_large', '')