basename with extensions

P

Peter Saffrey

I'd like to resurrect this subject:

http://groups.google.com/group/comp...14?lnk=gst&q=basename&rnum=2#6b2a3b0c0e902114

If I have a path like this:

mypath = /some/long/path/file.xml

and I want "file" I currently have to do:

os.path.basename(os.path.splitext(mypath)[0])

or use the slightly convoluted string method detailed in the groups
link above. An optional second argument to basename to remove a
specified extension, as is available in other languages like PHP and in
the shell version of basename, would seem pretty sensible.

Or have I missed something?

Peter
 
T

Tal Einat

Peter said:
I'd like to resurrect this subject:

http://groups.google.com/group/comp...14?lnk=gst&q=basename&rnum=2#6b2a3b0c0e902114

[snip]

Or have I missed something?
The Python developers are working on a new path module for the standard
library, since the current tools for working with paths are widely
accepted as being quite clumsy. Check out PEP 355 for details.

In the mean time, there are several alternative path modules you can
check out:

Jason Orendorff's path module:
http://www.jorendorff.com/articles/python/path/

PEP 355 reference implementation:
http://wiki.python.org/moin/PathModule

There are also others, to be found with Google.

- Tal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top