python os.path.split()和os.path.splitext()

os.path.split()将路径 path 拆分为一对,即 (head, tail),其中tail 是路径的最后一部分,而head 里是除最后部分外的所有内容。tail 部分不会包含斜杠,如果path以斜杠结尾,则tail 将为空。如果path中没有斜杠, head 将为空

os.path.splitext()分割路径,返回路径名和文件扩展名的元组

import os

file = 'E:/test/1.txt'
print(os.path.split(file))
print(os.path.splitext(file))

 

posted @ 2020-08-06 00:05  轩辕吊雷  阅读(294)  评论(0编辑  收藏  举报