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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Oct 7 00:57:04 CEST 2012


Antoine Pitrou wrote:

> True, but since we already have the name attribute it stands reasonable
> for basename to mean something else than name :-)
> Do you have another suggestion?

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).

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

Then if you really want to extract the last component without the
extension (which I expect to be a rare requirement), you can do

    path.with_ext("").name

-- 
Greg



More information about the Python-ideas mailing list