Hello,
I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?
print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:
m1 = r.match(l)
if m1:
ID=map(int,m1.group(2).split("."))
l = r.sub(r'\g<1>' + '.'.join(['%s' % (v) for v in ID]), l)
print ID
the results variable is:
Name Info Type Call version 1.0.40.437 Fri Oct 2 10:54:35 BST 2009
I have it done this way as I need the numbers in the ID separated into groups as I need to compare the 3rd number in the ID to the third number in the ID in another file.
The below answers are useful, but the way I had it would read a file and take all the numbers out and put them into a list so all I would have to do is compare the two numbers of the list. Sorry if the question was not clear but I don't want the version number to be a string.
Okay I made a couple of changes to the code that was answered below. The code is as follows:
version = re.compile('version\s+([\d.]+)\s+')
ID = version.search(results)
if ID:
value = ID.group(1).split('.')[2]
self.assertEqual(BUILD_ID[2], int(value))
This does not create the list that I wanted but it allows me to compare the 2 values.
Thanks for all the help.