发布时间:2022-08-09 文章分类:编程知识 投稿人:王小丽 字号: 默认 | | 超大 打印
up vote
32
down vote
accepted

Getting the name of the file without the extension :

import os
print os.path.splitext("path_to_file")[0]

As for your import problem, you solve it this way :

from os.path import basename
# now you can call it directly with basenameprint basename("/a/b/c.txt")