basename with extensions
Peter Saffrey
theoryboy at my-deja.com
Wed Aug 30 08:44:04 EDT 2006
I'd like to resurrect this subject:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/11146344b03e72b6/6b2a3b0c0e902114?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
More information about the Python-list
mailing list