Re: how to read the last line of a huge file???

2011-03-10 Thread tkp...@hotmail.com
There is a problem, and it's a Python 3.2 problem. All the solutions presented here work perfectly well in Python 2.7.1, and they all fail at exactly the same point in Python 3.2 - it's the line that tries to seek from the end. e.g. f.seek(offset, os.SEEK_END) I'll register this as a Python bug.

Re: how to read the last line of a huge file???

2011-03-05 Thread tkp...@hotmail.com
Thanks for the pointer. Yes, it is a text file, but the mystery runs deeper: I later found that it works perfectly as written when I run it from IDLE or the Python shell, but it fails reliably when I run it from PyScripter 2.4.1 (an open source Python IDE)! So I suspect there's a PyScripter issue

Re: how to read the last line of a huge file???

2011-03-05 Thread John Nagle
On 3/5/2011 10:21 AM, tkp...@hotmail.com wrote: Question: how do I use f.tell() to identify if an offset is legal or illegal? Read backwards in binary mode, byte by byte, until you reach a byte which is, in binary, either 0xxx 11xx You are then at the beginning of

Re: how to read the last line of a huge file???

2011-03-05 Thread Terry Reedy
On 3/5/2011 1:21 PM, tkp...@hotmail.com wrote: Thanks for the pointer. Yes, it is a text file, but the mystery runs deeper: I later found that it works perfectly as written when I run it from IDLE or the Python shell, but it fails reliably when I run it from PyScripter 2.4.1 (an open source

Re: how to read the last line of a huge file???

2011-03-04 Thread tkp...@hotmail.com
I've implementing this method of reading a file from the end, i.e def seeker(filename): offset = -10 with open(filename) as f: while True: f.seek(offset, os.SEEK_END) lines = f.readlines() if len(lines) = 2: return lines[-1]

Re: how to read the last line of a huge file???

2011-03-04 Thread MRAB
On 04/03/2011 21:46, tkp...@hotmail.com wrote: I've implementing this method of reading a file from the end, i.e def seeker(filename): offset = -10 with open(filename) as f: while True: f.seek(offset, os.SEEK_END) lines = f.readlines()

Re: how to read the last line of a huge file???

2011-03-04 Thread Ian Kelly
On Fri, Mar 4, 2011 at 5:26 PM, MRAB pyt...@mrabarnett.plus.com wrote: UnsupportedOperation: can't do non-zero end-relative seeks But offset is initialized to -10. Does anyone have any thoughts on what the error might be caused by? I think it's because the file has been opened in text mode,

Re: how to read the last line of a huge file???

2011-01-31 Thread Alan Meyer
On 01/26/2011 04:22 PM, MRAB wrote: On 26/01/2011 10:59, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... Seek to somewhere near the end

Re: how to read the last line of a huge file???

2011-01-31 Thread Kushal Kumaran
On Tue, Feb 1, 2011 at 9:12 AM, Alan Meyer amey...@yahoo.com wrote: On 01/26/2011 04:22 PM, MRAB wrote: On 26/01/2011 10:59, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use

Re: how to read the last line of a huge file???

2011-01-29 Thread Aahz
In article mailman.1412.1296196161.6505.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: file.seek takes an optional 'whence' argument which is 2 for the end, so you can just work back from there till you hit the first newline that has anything after it: def

Re: how to read the last line of a huge file???

2011-01-29 Thread Tim Chase
On 01/26/2011 04:59 AM, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... I wrote a modestly tested version (including missing

Re: how to read the last line of a huge file???

2011-01-29 Thread John O'Hagan
On Sat, 29 Jan 2011, Aahz wrote: In article mailman.1412.1296196161.6505.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: [...] def lastline(filename): offset = 0 line = '' with open(filename) as f: while True: offset -= 1

Re: how to read the last line of a huge file???

2011-01-28 Thread kost BebiX
26.01.2011, 12:59, Xavier Heruacles xheruac...@gmail.com: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... --

Re: how to read the last line of a huge file???

2011-01-27 Thread Alice Bevan–McGregor
On 2011-01-26 02:59:26 -0800, Xavier Heruacles said: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... This is not optimum or efficient, but it works! If you

Re: how to read the last line of a huge file???

2011-01-27 Thread Roy Smith
In article mailman.1353.1296119065.6505.python-l...@python.org, Alice Bevan–McGregor al...@gothcandy.com wrote: On 2011-01-26 02:59:26 -0800, Xavier Heruacles said: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line??

Re: how to read the last line of a huge file???

2011-01-27 Thread kost BebiX
27.01.2011, 15:55, Roy Smith r...@panix.com: In article mailman.1353.1296119065.6505.python-l...@python.org;,  Alice Bevan–McGregor al...@gothcandy.com; wrote:  On 2011-01-26 02:59:26 -0800, Xavier Heruacles said:  I have do some log processing which is usually huge. The length of each  line

Re: how to read the last line of a huge file???

2011-01-27 Thread John O'Hagan
On Wed, 26 Jan 2011, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... file.seek takes an optional 'whence' argument which is 2 for the

how to read the last line of a huge file???

2011-01-26 Thread Xavier Heruacles
I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... -- http://mail.python.org/mailman/listinfo/python-list

Re: how to read the last line of a huge file???

2011-01-26 Thread Emile van Sebille
On 1/26/2011 2:59 AM Xavier Heruacles said... I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... seek -rw-rw1 autofax mail 1061716366 Jan 26 12:45

Re: how to read the last line of a huge file???

2011-01-26 Thread MRAB
On 26/01/2011 10:59, Xavier Heruacles wrote: I have do some log processing which is usually huge. The length of each line is variable. How can I get the last line?? Don't tell me to use readlines or something like linecache... Seek to somewhere near the end and then read use readlines(). If