reading a line in file

Brian McCann Brian.McCann at viziant.net
Mon Aug 20 21:02:59 CEST 2007


 
Hi Tim,
The sample data is in file build.number

contents of file build.number:
 
 #Build Number for ANT. Do not edit!
 #Mon Aug 20 04:04:51 EDT 2007
build.number=1
 
Thanks,
Brian
 

________________________________

From: tdwdotnet at gmail.com on behalf of Tim Williams
Sent: Mon 8/20/2007 2:59 PM
To: Brian McCann
Cc: python-list at python.org
Subject: Re: reading a line in file



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 :)


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


More information about the Python-list mailing list