[Python-ideas] PEP 428 - object-oriented filesystem paths

Ben Finney ben+python at benfinney.id.au
Sun Oct 7 03:13:23 CEST 2012

Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> If we have a method for replacing the extension, I don't think
> we have a strong need a name for "all of the last name except the
> extension", because usually all you want that for is so you can add
> a different extension (possibly empty).

This is based on the false concept that there is one “extension” in a
filename. On POSIX filesystems, that's just not true; filenames often
have several suffixes in sequence, e.g. ‘foo.tar.gz’ or ‘foo.pg.sql’,
and each one conveys meaningful intent by whoever named the file.

> So I propose to avoid the term "basename" altogether, and just
> have
>    path.name --> all of the last component
>    path.ext --> the extension
>    path.with_name(foo) -- replaces all of the last component
>    path.with_ext(ext) -- replaces the extension

+1 on avoiding the term “basename” for anything to do with the concept
being discussed here, since it already has a different meaning (“the
part of the filename without any leading directory parts”).

−1 on entrenching this false concept of “the extension” of a filename.

 \          Eccles: “I'll get [the job] too, you'll see. I'm wearing a |
  `\        Cambridge tie.”  Greenslade: “What were you doing there?”  |
_o__)   Eccles: “Buying a tie.” —The Goon Show, _The Greenslade Story_ |
Ben Finney

More information about the Python-ideas mailing list