os.path.splitext(file)[0]
#Using pathlib in Python 3.4+ from pathlib import Path Path('/root/dir/sub/file.ext').stem