>>> a='/root/pythondemo/demo12/stringcut'
>>> a.split('/')[-1]
'stringcut'
>>> import os.path
>>> os.path.basename(a)
'stringcut'
>>> a.split('/')[-1]
'stringcut'
>>> import os.path
>>> os.path.basename(a)
'stringcut'
本文介绍如何使用Python标准库中的os.path模块以及字符串方法来获取文件路径中的文件名部分。通过两个示例展示了获取路径中文件名的具体实现方式。
8489

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