赞
踩
获取路径中的文件名
一、字符串分割–split()函数
path=“K:\Project\FilterDriver\DriverCodes\hello.txt”
print(path.split(’\’)[-1])
二。使用basename()函数
import os.path
filePath=“K:/Project/FilterDriver/DriverCodes/hello.txt”
print(os.path.basename(filePath))
执行的结果仍然是hello.txt。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。