reading a line in file

Brian McCann Brian.McCann at viziant.net
Mon Aug 20 14:52:16 EDT 2007


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

 

________________________________

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



Write some code, even if it doesn't quite work, and post it. We'll
help you fix it.

You can open a file with:  input = open("file.txt", "r")

You can read a line with: someText = input.readline()

You can loop through an open file like this:

for line in input:
    #do something with line


That should get you started.
--
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/2d76dc81/attachment.html>


More information about the Python-list mailing list