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.
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
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
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
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]
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()
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,
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
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
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
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
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
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... --
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
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??
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
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
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
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
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
20 matches
Mail list logo