On Sun, 27 Apr 2008 15:06:54 +0000, Matt Nordhoff wrote: > Arnaud Delobelle wrote: >> More simply, use the rsplit() method of strings: >> >>>>> path = r'C:\myimages\imageone.jpg' >>>>> path.rsplit('.', 1) >> ['C:\\myimages\\imageone', 'jpg'] >> >> >>>>> path = r"C:\blahblah.blah\images.20.jpg" >>>>> path.rsplit('.', 1) >> ['C:\\blahblah.blah\\images.20', 'jpg'] >> >> HTH > > There's os.path.splitext(), which probably does just about exactly that.
Not exactly. In the case of no extension `os.path.splitext()` still works: In [14]: 'foo/bar.txt'.rsplit('.') Out[14]: ['foo/bar', 'txt'] In [15]: 'foo/bar'.rsplit('.') Out[15]: ['foo/bar'] In [16]: os.path.splitext('foo/bar') Out[16]: ('foo/bar', '') Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list