import os
p=os.path.dirname('C:\\win\\yes\\text.txt')
print p
print os.path.split(p+"\\")#目录与文件分离
print os.path.split(p)

print os.path.dirname(p)#the first half of the pair returned by split(path).
print os.path.basename(p)#the second half of the pair returned by split(path).

print os.path.normcase('C:\\win\\yes\\..\\..')#将正斜杠换位反斜杠
print os.path.normcase('/usr/var/../')

print os.path.normpath('/usr/var/../yes.c')#序列化路径,去除上一个目录(../)与当前目录(./)
print os.path.normpath('C:\\win\\yes\\..\\..')

 输出:

C:\win\yes
('C:\\win\\yes', '')
('C:\\win', 'yes')
C:\win
yes
c:\win\yes\..\..
\usr\var\..\
\usr\yes.c
C:\

相关文章:

  • 2021-09-22
  • 2022-12-23
猜你喜欢
  • 2021-08-15
  • 2022-12-23
  • 2021-09-23
  • 2019-02-15
  • 2021-11-07
相关资源
相似解决方案