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

parsing a file name

P: n/a
I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
thanks

Jan 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 12 Jan 2007 09:16:51 -0800, CSUIDL PROGRAMMEr <sy*********@yahoo.comwrote:
I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
thanks

--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to think of a good reason to extract the version from the
filename instead of using RPM to get the real version from the
metadata and I can't come up with one.
Jan 12 '07 #2

P: n/a
Chris Mellon wrote:
>
I'm trying to think of a good reason to extract the version from the
filename instead of using RPM to get the real version from the
metadata and I can't come up with one.
The inquirer doesn't have any RPM handling tools installed/available or
is dealing with a lot of versioned filenames which might be a selection
of different, arbitrary formats.

Try harder! ;-)

Paul

Jan 12 '07 #3

P: n/a
On 12 Jan 2007 10:23:41 -0800, Paul Boddie <pa**@boddie.org.ukwrote:
Chris Mellon wrote:

I'm trying to think of a good reason to extract the version from the
filename instead of using RPM to get the real version from the
metadata and I can't come up with one.

The inquirer doesn't have any RPM handling tools installed/available or
is dealing with a lot of versioned filenames which might be a selection
of different, arbitrary formats.

Try harder! ;-)

Paul
Well, the answer to the first is "get some", so that's not a good
reason. And the second would mean that they asked a question on c.l.p
without giving all the background information on the task they were
doing, and we know that never happens.
Jan 12 '07 #4

P: n/a
CSUIDL PROGRAMMEr wrote:
I have a filename
cairo-2.3.4.src.rpm
Is there any way i can only get 2.3.4 from this file name
>>a = "cairo-2.3.4.src.rpm"
import re
re.compile(r"\d+([.]\d+)*").search(a).group(0)
'2.3.4'
>>a.split("-")[-1][:-len(".src.rpm")]
'2.3.4'
>>".".join(map(str, range(2, 5)))
'2.3.4'

--
Roberto Bonvallet
Jan 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.