read lines

2007-12-04 Thread Horacius ReX
Hi, I have a text file like this; 1 -33.453579 2 -148.487125 3 -195.067172 4 -115.958374 5 -100.597841 6 -121.566441 7 -121.025381 8 -132.103507 9 -108.939327 10 -97.046703 11 -52.866534 12 -48.432623 13 -112.790419 14 -98.516975 15 -98.724436 So I want to write a program in python that reads

Re: read lines

2007-12-04 Thread Chris
On Dec 4, 2:14 pm, Horacius ReX [EMAIL PROTECTED] wrote: Hi, I have a text file like this; 1 -33.453579 2 -148.487125 3 -195.067172 4 -115.958374 5 -100.597841 6 -121.566441 7 -121.025381 8 -132.103507 9 -108.939327 10 -97.046703 11 -52.866534 12 -48.432623 13 -112.790419 14

Re: read lines

2007-12-04 Thread Zepo Len
Hi, I have a text file like this; 1 -33.453579 2 -148.487125 So I want to write a program in python that reads each line and detects which numbers of the second column are the maximum and the minimum. I tried with; import os, sys,re,string # first parameter is the name of the

Re: read lines

2007-12-04 Thread Neil Cerutti
On 2007-12-04, Horacius ReX [EMAIL PROTECTED] wrote: Hi, I have a text file like this; 1 -33.453579 2 -148.487125 3 -195.067172 4 -115.958374 5 -100.597841 6 -121.566441 7 -121.025381 8 -132.103507 9 -108.939327 10 -97.046703 11 -52.866534 12 -48.432623 13 -112.790419 14 -98.516975

Re: read lines

2007-12-04 Thread Piet van Oostrum
Horacius ReX [EMAIL PROTECTED] (HR) wrote: HR while 1: HR line = infile1.readline() You have an infinite loop. Fortunately your program stops because of the error. When you encounter end of file, line becomes the empty string and the split gives you only 1 item instead of 2. So add

Re: read lines

2007-12-04 Thread Zepo Len
Your regex is not working correctly I guess, I don't even know why you are using a regex, something like this would work just fine: import sys nums = [float(line.split(' -')[1]) for line in open(sys.argv[1])] print 'min=', min(nums), 'max=', max(nums) Sorry, that should be line.split() -

Re: read lines

2007-12-04 Thread Bruno Desthuilliers
Chris a écrit : On Dec 4, 2:14 pm, Horacius ReX [EMAIL PROTECTED] wrote: Hi, I have a text file like this; 1 -33.453579 2 -148.487125 3 -195.067172 4 -115.958374 5 -100.597841 6 -121.566441 7 -121.025381 8 -132.103507 9 -108.939327 10 -97.046703 11 -52.866534 12 -48.432623 13

Re: read lines

2007-12-04 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : (snip) # Notice that here, b is a string, not a number... try: b = int(tmp[1]) oops, I meant: b = float(tmp[1]) Idem here: def extract_number(iterable): for linenum, line in enumerate(iterable): try:

Re: read lines

2007-12-04 Thread Peter Otten
Bruno Desthuilliers wrote: # You don't need to read the whole file in memory lines1, lines2 = tee(infile) print min(extract_numbers(lines1)), max(extract_numbers(lines2)) tee() internally maintains a list of items that were seen by one but not all of the iterators returned. Therefore after

Re: read lines

2007-12-04 Thread Bruno Desthuilliers
Peter Otten a écrit : Bruno Desthuilliers wrote: # You don't need to read the whole file in memory lines1, lines2 = tee(infile) print min(extract_numbers(lines1)), max(extract_numbers(lines2)) tee() internally maintains a list of items that were seen by one but not all of the iterators