Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

basename and .ext

10 views
Skip to first unread message

Paul Watson

unread,
Mar 3, 2003, 7:26:58 PM3/3/03
to
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?


Pad...@linux.ie

unread,
Mar 4, 2003, 6:37:55 AM3/4/03
to

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.

0 new messages