import os
def custombasename(fullname):
return os.path.basename(os.path.splitext(fullname)[0])
a = 'var/label/txt/123.txt'
print(custombasename(a))
print(os.path.splitext(a))
print(os.path.splitext(a)[0])
print(os.path.basename(os.path.splitext(a)[0])) # 取1个path的最后名称
# 同理,先取最后文件名,再得到无后缀名称
print(os.path.basename(a))
print(os.path.splitext(os.path.basename(a))[0])
123
('var/label/txt/123', '.txt')
var/label/txt/123
123
123.txt
123
网友评论