basename and .ext
Padraig at Linux.ie
Padraig at Linux.ie
Tue Mar 4 06:37:55 EST 2003
Paul Watson wrote:
> I would like to see os.path.basename() have an optional second parameter for
> a filename extension. This would be more similar to the UNIX basename
> command.
>
> Does anyone else see this as a good idea?
Well if you don't know the extension you have
the more powerful os.path.splitext().
If you do know the extension then just
use the standard python functionality:
f='file.tar.gz'
if f.endswidth('.tar.gz'):
f=f[:-len('.tar.gz')
It's better not to duplicate the logic I think.
Pádraig.
More information about the Python-list
mailing list