os.path.splitext(“文件路径”)

  • 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', '')
    



你可能感兴趣的:(python)