pyhton remove extension string code example Example: file base name and extension python from pathlib import Path Path('/root/dir/sub/file.ext').stem