Lie <[EMAIL PROTECTED]> writes: > On Apr 27, 6:05 pm, Lie <[EMAIL PROTECTED]> wrote: >> >> I don't know if this is the simplest way, but you can use re module. >> >> import re >> pat = re.compile(r'(.*?)\..*') > > Sorry, this line should be: > pat = re.compile(r'(.*)\..*') > > or paths like these wouldn't pass correctly: > "C:\\blahblah.blah\\images.20.jpg" > >> name = pat.search('C:\\myimages\\imageone.jpg').group(1) >> print name
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 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list