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