API文档:
- os.path.split(path)
- Split the pathname path into a pair, (head, tail) where tail is the last pathname component andhead is everything leading up to that. Thetail part will never contain a slash; ifpath ends in a slash, tail will be empty. If there is no slash inpath, head will be empty. Ifpath is empty, both head andtail are empty. Trailing slashes are stripped fromhead unless it is the root (one or more slashes only). In all cases,join(head,tail) returns a path to the same location as path (but the strings may differ).
翻译文档:
将文件和文件路径进行分离,返回(path,filename)这样一个的元组
如果path中不包含文件文件名则返回(path,''),如果path中不包含路径则返回('',fileName)
例子:
import os
pathStr = 'F:\\pyWorkSpace\\notes\\dPython\\music\\_singles\\aa.mp3'
print os.path.split(pathStr)
print type(os.path.split(pathStr))
(filePath,fileName)=os.path.split(pathStr)
print filePath
print fileName
print os.path.split('aa.mp3')
print os.path.split('C:\\')
输出:
('F:\\pyWorkSpace\\notes\\dPython\\music\\_singles', 'aa.mp3')
<type 'tuple'>
F:\pyWorkSpace\notes\dPython\music\_singles
aa.mp3
('', 'aa.mp3')
('C:\\', '')