basename and .ext

Padraig at Padraig at
Tue Mar 4 12:37:55 CET 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:

if f.endswidth('.tar.gz'):

It's better not to duplicate the logic I think.


More information about the Python-list mailing list