Re: reading a line in file

2007-08-21 Thread Neil Cerutti
On 2007-08-20, Shawn Milochik <[EMAIL PROTECTED]> wrote: > Everybody hates regexes. Except me. Discrimination! I love them when I'm editing files with Vim, hate 'em when I'm analyzing files with Python code. So I'm a descriminate descriminator. -- Neil Cerutti The First World War, cause by the

Re: reading a line in file

2007-08-20 Thread Tim Williams
On 20/08/07, Brian McCann <[EMAIL PROTECTED]> wrote: > > 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 Hi Brian, > bu

Re: reading a line in file

2007-08-20 Thread Jay Loden
Shawn Milochik wrote: > Although you're technically correct, I think there's a knee-jerk > anti-regex reaction, citing the meaningless overhead. If you're > running many thousands of records or something then it becomes a small > issue compared to a replace statement or something. But in most cases

RE: reading a line in file

2007-08-20 Thread Brian McCann
db.connstr=jdbc:oracle:thin:@127.0.0.1:1521:XE From: [EMAIL PROTECTED] on behalf of Shawn Milochik Sent: Mon 8/20/2007 4:35 PM To: python-list@python.org Subject: Re: reading a line in file Although you're technically correct, I think there's a

Re: reading a line in file

2007-08-20 Thread Shawn Milochik
Although you're technically correct, I think there's a knee-jerk anti-regex reaction, citing the meaningless overhead. If you're running many thousands of records or something then it becomes a small issue compared to a replace statement or something. But in most cases it makes no difference at all

Re: reading a line in file

2007-08-20 Thread Jay Loden
Shawn Milochik wrote: > Everybody hates regexes. Except me. Discrimination! Actually, I love them, they are an amazingly powerful tool. I just happen to also believe the old axiom "when all you have is a hammer, everything looks like your thumb". Also the related "some people think when they see

Re: reading a line in file

2007-08-20 Thread Shawn Milochik
Everybody hates regexes. Except me. Discrimination! -- http://mail.python.org/mailman/listinfo/python-list

Re: reading a line in file

2007-08-20 Thread Jay Loden
Brian McCann wrote: > 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

RE: reading a line in file

2007-08-20 Thread Brian McCann
Brian From: [EMAIL PROTECTED] on behalf of Shawn Milochik Sent: Mon 8/20/2007 3:07 PM To: python-list@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 =

Re: reading a line in file

2007-08-20 Thread Jay Loden
Shawn Milochik 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 li

Re: reading a line in file

2007-08-20 Thread Tim Williams
On 20/08/07, Shawn Milochik <[EMAIL PROTECTED]> 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(reg

Re: reading a line in file

2007-08-20 Thread Tim Williams
On 20/08/07, Brian McCann <[EMAIL PROTECTED]> wrote: > > > > > From: [EMAIL PROTECTED] on behalf of Tim Williams > Sent: Mon 8/20/2007 2:59 PM > To: Brian McCann > Cc: python-list@python.org > Subject: Re: reading a line in file &g

Re: reading a line in file

2007-08-20 Thread Shawn Milochik
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.numbe

RE: reading a line in file

2007-08-20 Thread Brian McCann
To: Brian McCann Cc: python-list@python.org Subject: Re: reading a line in file On 20/08/07, Brian McCann <[EMAIL PROTECTED]> 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 as

Re: reading a line in file

2007-08-20 Thread Tim Williams
On 20/08/07, Brian McCann <[EMAIL PROTECTED]> 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

RE: reading a line in file

2007-08-20 Thread Brian McCann
e 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: [EMAIL PROTECTED] on behalf of Shawn Milochik Sent: Mon 8/20/2007 1:29 PM To: python-list@python.org Subject: Re: reading a line in file Writ

reading a line in file

2007-08-20 Thread Brian McCann
Hi, does anyone have a good example of how to read a line in a file? say you have a file build.log and in the file are values like buildnum = 1 date = 20070820 I know how to read the contents and write them to a file, but how would one grab just the date or build number in order to create a

Re: reading a line in file

2007-08-20 Thread Shawn Milochik
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 s