Path 对象

63.1 Path 对象

Path 表示文件或目录路径,支持 / 拼接。

拼接与判断

from pathlib import Path
p = Path('data') / 'scores.txt'
print(p)
print(p.suffix)   # .txt
print(p.stem)     # scores