浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

string - How to get the filename without the extension from a path in Python? - Stack Overflow

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 basename
print basename("/a/b/c.txt")
posted on 2012-06-05 09:08  lexus  阅读(674)  评论(0)    收藏  举报