<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3492" name=GENERATOR></HEAD>
<BODY><!-- Converted from text/plain format -->
<P><FONT size=2>Hi,<BR><BR>I am getting the error <FONT face=Courier
size=1>TypeError: seek() takes exactly 2 arguments (3 given),<FONT
face="Times New Roman" size=2> namely:</FONT></FONT><BR><BR><FONT
face=Courier><FONT size=1>$
./_LogStream.py <BR>Traceback
(most recent call last):<BR> File "./_LogStream.py", line 47, in
<module><BR>
log_stream.last_line_loc_and_contents()<BR> File "./_LogStream.py", line
20, in last_line_loc_and_contents<BR> self.input_file.seek(-1,
2) # grab the last character<BR>TypeError: seek() takes exactly 2 arguments (3
given)</FONT><BR></FONT><BR>When I run the below code.<BR> <BR>I understand
that the extra argument is the "self", but I don't know how to change my class
to make the seek(-1,2) work.<BR><BR>Could you help
?<BR><BR>Thanks,<BR>Ron.<BR></FONT></P>
<P><FONT size=2><FONT face=Courier><FONT size=1>$ cat
_LogStream.py<BR>#!/usr/bin/env python<BR><BR>import gzip<BR>import
sys<BR><BR>from Debug import _line as line<BR><BR>class
LogStream():<BR> <BR> def __init__(self,
filename):<BR> self.filename =
filename<BR> self.input_file =
self.open_file(filename)<BR>
self.index_increment = 10<BR>
self.last_line_offset = -1<BR><BR> def
last_line_loc_and_contents(self,
estimated_line_size=1024):<BR><BR>
assert estimated_line_size > 0<BR>
file_size =
len(self.input_file.read())<BR>
self.input_file.seek(-1, 2) # grab the last
character<BR><BR> if
self.input_file.read(1) == '\n': # a "proper" text
file<BR>
file_size -= 1<BR><BR> def open_file(self,
in_file):<BR>
"""<BR> The gzip module checks if the
input file is a gzipped file, only at the read
stage.<BR> This is why the
f.readline() is needed.<BR>
"""<BR>
try:<BR> f =
gzip.GzipFile(in_file,
"r")<BR>
f.readline()<BR> except
IOError:<BR> f
= open(in_file,
"r")<BR>
f.readline()<BR><BR>
f.seek(0)<BR> return(f)<BR><BR><BR>if
__name__ == "__main__":<BR> filename =
"../save_state/hp/save_state-ssp8400-0709R00004_081126-121659/var/log\\sac.log.4.gz"<BR>
log_stream = LogStream(filename)<BR> log_stream.limit_ =
1000<BR> log_stream.index_increment =
12<BR><BR>
log_stream.last_line_loc_and_contents()<BR></FONT></P></FONT></FONT></BODY></HTML>