In Python 3.4+, you can use the pathlib module (included in Python's standard library):
pathlib
>>> from pathlib import Path >>> p = Path("/home/user/Downloads/repo/test.txt") >>> print(p.stem) test >>> print(p.name) test.txt
548k questions
547k answers
4 comments
86.3k users