You could use a
Path
from pathlib
and use the method stem
to get the final path component, minus its last suffix.import pathlib fname = "abc.xlsx" path = pathlib.Path(fname) print(path.stem)
Output:abc