reading a line in file

Tim Williams tdwdotnet at gmail.com
Mon Aug 20 15:32:54 EDT 2007


On 20/08/07, Shawn Milochik <Shawn at milochik.com> wrote:
> 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
> --

If I misunderstood the original post and the build number is all that
is required from the file, then:

buildNum =  open('input.txt').read().split('build.number=')[1].split()[0]

:)



More information about the Python-list mailing list