首页 > 技术文章 > Python 判断文件后缀

geoffreyone 2019-04-24 12:43 原文

方法1, str的endswith方法:

ims_path='data/market1501/Market-1501-v15.09.15/bounding_box_test/12312.jpg'
ims_path.endswith('.jpg')

返回结果: True
应用:判断后缀名的示例:

2. 方法2, os.path.splitext() 方法:

该方法返回两个元素, 第一个是路径去掉后缀的部分, 第二个是文件后缀:

推荐阅读