1.os.path.basename(in_path.decode(“utf8”))返回最后当前文件名
#coding=utf-8
import os
print os.path.abspath("d:\\new\\test.txt") #d:\new\test.txt
print os.path.basename("d:\\new\\test.txt") #test.txt
print os.path.dirname("d:\\new\\test.txt") #d:\new
print os.path.exists("d:\\new") #True
print os.path.lexists("d:\\new") #True
print os.path.expanduser("d:\\new\\text.txt") #d:\new\text.txt
print os.path.getatime("d:\\new") #最后访问时间
print os.path.getmtime("d:\\new") #最后修改路径时间
print os.path.getctime("d:\\new") #创建时间
print os.path.getsize("d:\\new\\") #或许路径的大小 字节为单位
print os.path.isabs("d:\\") #是否是绝对路径
print os.path.isfile("d:\\new\\hello.txt")
print os.path.isdir("d:\\new")
print os.path.islink("d:\\new\\hello.txt")
print os.path.join("d:\\new","hello.txt")
print os.path.normcase("d:\\new\\hello.txt")
print os.path.relpath("d:\\new\\hello.txt") #相对路径
print os.path.split("d:\\new\\hello.txt") #分离文件名
print os.path.splitdrive("d:\\new\\hello.txt") #分离磁盘驱动器
print os.path.splitext("d:\\new\\hello.txt") #分离扩展名
os.path.splitext()
split() 用于返回目录路径和文件名的元组
import os
os.path.split('d:\\library\\book.txt') #输出('d:\\library', 'book.txt')
splitdrive() 用于返回盘符和路径字符元组
os.path.splitdrive('d:\\library\\book.txt') #输出('d:', '\\library\\book.txt')
splitext() 用于返回文件名和扩展名元组
os.path.splitext('d:\\library\\book.txt')('d:\\library\\book', '.txt')
os.path.splitext('book.txt')('book', '.txt')
所以os.path.splitext(os.path.basename(in_path.decode(“utf8”)))有什么作用
os.path.basename("d:\\new\\book.txt")
os.path.splitext('book.txt')('book', '.txt')
能够得到当前路径下的文件名~
本文详细介绍了Python中os.path模块的功能及使用方法,包括获取文件名、路径、判断路径有效性等实用函数的应用示例。
1344

被折叠的 条评论
为什么被折叠?



