reading a line in file

Brian McCann Brian.McCann at viziant.net
Mon Aug 20 15:54:07 EDT 2007


Shawn, Tim ,Jay
 
many thanks,
 
It looks like there are many ways this problem can be approached

either by using  regex or a tokens 

Tim I'm not familiar with your solution, but will learn about that method also
Jay, what do you mean by regex comes with a lot of overhead?

--Brian
 
 

________________________________

From: python-list-bounces+brian.mccann=viziant.net at python.org on behalf of Shawn Milochik
Sent: Mon 8/20/2007 3:07 PM
To: python-list at python.org
Subject: Re: reading a line in file



Hopefully this will help (using your input file)

#!/usr/bin/env python
import re
buildinfo = "input.txt"
input = open(buildinfo, 'r')

regex = re.compile(r"^\s*build.number=(\d+)\s*$")

for line in input:
    if re.search(regex, line):
        print line
        buildNum = re.sub(r"^\s*build.number=(\d+)\s*$", "\\1", line)
        print line
        print buildNum
--
http://mail.python.org/mailman/listinfo/python-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070820/dec0ee59/attachment.html>


More information about the Python-list mailing list