Answers for "get file extension pathlib"

2

python get file extension from path

import os.path
extension = os.path.splitext(filename)[1]
Posted by: Guest on May-08-2020
0

pathlib path get filename with extension

>>> from pathlib import Path
>>> p = Path("/home/user/Downloads/repo/test.txt")
>>> print(p.stem)
test
>>> print(p.name)
test.txt
Posted by: Guest on May-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language