os path basename remove extension code example
Example 1: strip file extension python
import os
print(os.path.splitext("/path/to/some/file.txt")[0])
Example 2: file base name and extension python
from pathlib import Path
Path('/root/dir/sub/file.ext').stem