reading a line in file

Tim Williams tim at tdw.net
Mon Aug 20 20:59:21 CEST 2007


On 20/08/07, Brian McCann <Brian.McCann at viziant.net> wrote:
>
> Hi,
>
> I can read in the whole file build.number which has the following lines
> how do I just capture the value of build.number and assign it to a variable
> Thanks,
> Brian
>
> contents of file build.number:
> #Build Number for ANT. Do not edit!
> #Mon Aug 20 04:04:51 EDT 2007
> build.number=1
> buildinfo.py
> ##################################
> #!/usr/bin/python
> import string
> import os
> import sys
> import time
> import errno
> import shutil
> buildinfo = "build.number"
> input = open(buildinfo, 'r')
> for line in input:
>         print line
> #########################################
>
> command line when script is run
> $ buildinfo.py
> #Build Number for ANT. Do not edit!
>
> #Mon Aug 20 04:04:51 EDT 2007
> build.number=1
>
>

This is preferred nowadays

for line in open(buildinfo):
        print line

Without a sample of the data, no-one can help you further.   If this
is homework, you should say so, people will give you guidance :)



More information about the Python-list mailing list