Getting the filename using Python's pathlib

Path(path/to/filename.file_extension).stem gives filename.