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. T
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 Pytho
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 a
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 l
On Fri, Mar 4, 2011 at 5:26 PM, MRAB 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, so there's
> the
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()
if
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 Tue, Feb 1, 2011 at 9:12 AM, Alan Meyer 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
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 Sat, 29 Jan 2011, Aahz wrote:
> In article ,
>
> John O'Hagan wrote:
[...]
> >
> >def lastline(filename):
> >offset = 0
> >line = ''
> >with open(filename) as f:
> >while True:
> >offset -= 1
> >f.seek(offset, 2)
> >nextline = f.next()
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
terminal-EO
In article ,
John O'Hagan 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 lastline(filename):
>offset = 0
>line = ''
>with open(filename) as f:
>
26.01.2011, 12:59, "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
Well, it's
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
27.01.2011, 15:55, "Roy Smith" :
> In article ;,
> Alice Bevan–McGregor ; 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?? Don't tell me to use
>>> re
In article ,
Alice BevanâMcGregor 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?? 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 wa
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 you
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 au
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
20 matches
Mail list logo