By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

how to remove suffix from filename

P: n/a

hi
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
RG
Mar 19 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mel
royG wrote:
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
os.path.splitext is the one, it think.

Mar 19 '08 #2

P: n/a
royG wrote:
hi
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
RG
import os

fname='F:/mydir/two.jpg'
filenameonly=os.path.splitext(os.path.basename(fna me))[0]

-Larry
Mar 19 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.