os.path

os.path.split()

import os

path = r'C:\Users\Public\book.txt'
(head, tail) = os.path.split(path)
print(head, tail)
# C:\Users\Public book.txt

os.path.splitext()

import os

path = r'C:\Users\Public\book.txt'
(root, ext) = os.path.splitext(path)
print(root, ext)
# C:\Users\Public\book .txt

 
 
参考
os.path — Common pathname manipulations

posted @ 2022-04-14 17:07  Soldier&Justice  阅读(43)  评论(0编辑  收藏  举报