[python] pathlib.Path.stem 获取文件名,不要后缀名. getting filename, no extension

 

Python 3.4+

Use pathlib.Path.stem

>>> from pathlib import Path
>>> Path("/path/to/file.txt").stem
'file'
>>> Path("/path/to/file.tar.gz").stem
'file.tar'

 

参考:https://stackoverflow.com/questions/678236/how-do-i-get-the-filename-without-the-extension-from-a-path-in-python#678242

 

posted @ 2024-11-14 18:21  profesor  阅读(1)  评论(0编辑  收藏  举报