[Python-Dev] Proposal to revert r54204 (splitext change)

Delaney, Timothy (Tim) tdelaney at avaya.com
Wed Mar 14 22:47:15 CET 2007


Michael Foord wrote:

> There was code posted that used the (almost entirely sane) pattern :
> 
> new_filename  = os.path.splitext(old_filename)[1] + '.bak'
> 
> That was broken but is now fixed. It follows the entirely natural
> assumption that filename without an extension would not have the
> filename put in the extension half of the tuple.

Well, I'd argue the sanity of it, but you're right - it was posted.

> The documentation (not the docstring) actually says :
> 
> splitext( path)
> 
>     Split the pathname path into a pair (root, ext) such that root +
> ext == path, and ext is empty or begins with a period and contains at
> most one period.
> 
> Even the docstring only states that either part may be empty, hardly
> documenting what is clearly a misfeature.

splitext(p)
    Split the extension from a pathname.

    Extension is everything from the last dot to the end.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Return (root, ext), either part may be empty.

That's pretty explicit.

Tim Delaney


More information about the Python-Dev mailing list