<!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.3462" name=GENERATOR></HEAD>
<BODY><!-- Converted from text/plain format -->
<P> <FONT face=Arial>Hi,</FONT></P>
<P><FONT face=Arial>When using seek() with a certain text file, I get strange 
results.<BR>I looked at the text file with a binary editor and verified with 
'file', and it's an ASCII English text file.</FONT></P>
<P><FONT face=Arial>Running the script on other text files gives the expected 
output.</FONT></P>
<P><FONT face=Arial><EM>Could you suggest the reason ?</EM></FONT></P>
<P><FONT face=Arial>In the outputs below, when using </FONT><FONT 
face="Courier New" size=1>generator.py <FONT face=Arial size=3>as input for 
</FONT>generator.py <FONT face=Arial size=3>the 'diff' is a nice 
progression as expected. ('diff' is the difference between the file pointer 
location and the number of characters read up to 
now).<BR><BR></FONT></FONT><FONT face="Courier New" size=1><FONT face=Arial 
size=3>However, when using <FONT face="Courier New" size=1>sac.log <FONT 
face=Arial size=3>as input for </FONT>generator.py <FONT face=Arial 
size=3>the 'diff' is a strange series: 1, 2, 1, 2, 3, 4, 5, 
6<BR><BR></FONT></FONT></FONT></FONT><FONT face="Courier New" size=1><FONT 
face=Arial size=3>Running <FONT face="Courier New" 
size=1>generator.py <FONT face=Arial size=3>on a bigger portion of <FONT 
face="Courier New" size=1>sac.log </FONT>produces these 
'diff's:</FONT></FONT><BR> 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 
25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 
24, 25, 26, 27, 28, 29, 30, 31, 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 
26, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 
22, 23, 24, 25, 26, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1, 2, 3, 4, 
5, 6, 7, 8, 9, 10</FONT></FONT><FONT face="Courier New" size=1><FONT face=Arial 
size=3></P></FONT></FONT>
<P><FONT face=Arial>Thanks,<BR>Ron.</FONT></P><FONT face="Courier New" 
size=1><FONT face=Arial size=3>
<P>
<HR>
</P></FONT></FONT>
<P><FONT face="Courier New" size=1>$ <STRONG>cat -n generator.py 
<BR></STRONG>     1  #!/usr/bin/env 
python<BR>     2<BR>     3  import 
gzip<BR>     4  import sys<BR>     
5  from Debug import _line as line<BR>     
6<BR>     7  class 
LogStream():<BR>     8      
<BR>     9      def __init__(self, 
filename):<BR>    
10          self.filename = 
filename<BR>    
11          self.input_file = 
self.open_file(filename)<BR>    12<BR>    
13      def open_file(self, 
in_file):<BR>    
14          
try:<BR>    
15              
f = gzip.GzipFile(in_file, "r")<BR>    
16              
f.readline()<BR>    
17          except 
IOError:<BR>    
18              
f = open(in_file, "r")<BR>    
19              
f.readline()<BR>    
20          
f.seek(0)<BR>    
21          
return(f)<BR>    22<BR>    
23      def line_generator(self):<BR>    
24          while 
True:<BR>    
25              
line_ = self.input_file.readline()<BR>    
26              
print line()+". line_==|"+line_.strip()+"|"<BR>    
27              
self.total_chars += len(line_)<BR>    
28              
print line()+". line length:",len(line_),"; file 
pointer:",self.input_file.tell(),<BR>    
29              
print "; total chars:",self.total_chars,"; diff:",self.input_file.tell() - 
self.total_chars<BR>    
30              
if not line_:<BR>    
31                  
break<BR>    
32              
yield line_.strip()<BR>    33<BR>    
34<BR>    35  if __name__ == 
"__main__":<BR>    36<BR>    
37      filename = sys.argv[1]<BR>    
38      log_stream = 
LogStream(filename)<BR>    39      
log_stream.input_file.seek(0)<BR>    
40      log_stream.total_chars = 
0<BR>    41      line_generator = 
log_stream.line_generator()<BR>    
42      for i in range(8):<BR>    
43          line_ = 
line_generator.next() <BR></FONT></P>
<P><FONT face="Courier New" size=1>$ <STRONG>python generator.py 
generator.py    <BR></STRONG>26. line_==|#!/usr/bin/env 
python|<BR>28. line length: 22 ; file pointer: 23 ; total chars: 22 ; diff: 
1<BR>26. line_==||<BR>28. line length: 1 ; file pointer: 25 ; total chars: 23 ; 
diff: 2<BR>26. line_==|import gzip|<BR>28. line length: 12 ; file pointer: 38 ; 
total chars: 35 ; diff: 3<BR>26. line_==|import sys|<BR>28. line length: 11 ; 
file pointer: 50 ; total chars: 46 ; diff: 4<BR>26. line_==|from Debug import 
_line as line|<BR>28. line length: 32 ; file pointer: 83 ; total chars: 78 ; 
diff: 5<BR>26. line_==||<BR>28. line length: 1 ; file pointer: 85 ; total chars: 
79 ; diff: 6<BR>26. line_==|class LogStream():|<BR>28. line length: 19 ; file 
pointer: 105 ; total chars: 98 ; diff: 7<BR>26. line_==||<BR>28. line length: 5 
; file pointer: 111 ; total chars: 103 ; diff: 8</FONT></P>
<P><FONT face="Courier New" size=1>$ <STRONG>python generator.py 
sac.log</STRONG>                                                      
<BR>26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1714]: AGENT[0]:  
[tv_expand               
] tv_expand:........[Domain 5:DVol1_3CG1-MM-1229347528T0] 
maxVolCapacityMB:....[5121] tempVolCapacityMB:...[512] 
fivePercentMB:.......[256] expandedTempVolCap:..[1024]|<BR>28. line length: 246 
; file pointer: 247 ; total chars: 246 ; diff: 1<BR>26. line_==|Dec 15 15:45:20 
iSW-00-090 svm_sac[1714]: AGENT[0]:  [daemon_send_expand_reque] [Domain 
5:DVol1_3CG1-MM-1229347528T0]: Add expand request up to 1024 MB (2097152 
sectors)|<BR>28. line length: 170 ; file pointer: 418 ; total chars: 416 ; diff: 
2<BR>26. line_==|Dec 15 15:45:20 iSW-00-090 svm_sac[1746]: AGENT[0]:  
[domain_expand_exec      ] [Domain 
5:DVol1_3CG1-MM-1229347528T0]: Send expand up to 1024 MB (2097152 sectors): 
success|<BR>28. line length: 172 ; file pointer: 589 ; total chars: 588 ; diff: 
1<BR>26. line_==|Dec 15 15:45:21 iSW-00-090 svm_sac[1744]: AGENT[0]:  
[domain_poll             
] Domain [Domain 5]: SVM reported volume manager setup changed|<BR>28. line 
length: 141 ; file pointer: 731 ; total chars: 729 ; diff: 2<BR>26. line_==|Dec 
15 15:45:21 iSW-00-090 svm_sac[1744]: AGENT[0]:  
[domain_poll             
] Domain [Domain 5]: SVM reported multiview setup changed|<BR>28. line length: 
136 ; file pointer: 868 ; total chars: 865 ; diff: 3<BR>26. line_==|Dec 15 
15:45:21 iSW-00-090 svm_sac[1744]: AGENT[0]:  [domain_is_setup_changed ] 
Domain [Domain 5]: Setup CHANGED|<BR>28. line length: 113 ; file pointer: 982 ; 
total chars: 978 ; diff: 4<BR>26. line_==|Dec 15 15:45:21 iSW-00-090 
svm_sac[1744]: AGENT[0]:  
[domain_get_pages        ] Domain [Domain 5]: 
Asked to get setup pages|<BR>28. line length: 124 ; file pointer: 1107 ; total 
chars: 1102 ; diff: 5<BR>26. line_==|Dec 15 15:45:21 iSW-00-090 svm_sac[1744]: 
AGENT[0]:  
[svm_get_pages           ] SVM 
[Domain 5:12345]: got all setup pages|<BR>28. line length: 122 ; file pointer: 
1230 ; total chars: 1224 ; diff: 6<BR></FONT></P>
<P><FONT face="Courier New" size=1>$ <STRONG>cat generator.py 
<BR></STRONG>#!/usr/bin/env python</P>
<P><FONT face="Courier New" size=1>import gzip<BR>import sys<BR>from Debug 
import _line as line</FONT></P>
<P><FONT face="Courier New" size=1>class LogStream():<BR>    
<BR>    def __init__(self, 
filename):<BR>        self.filename = 
filename<BR>        self.input_file = 
self.open_file(filename)</FONT></P>
<P><FONT face="Courier New" size=1>    def open_file(self, 
in_file):<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>        
f.seek(0)<BR>        return(f)</FONT></P>
<P><FONT face="Courier New" size=1>    def 
line_generator(self):<BR>        while 
True:<BR>            
line_ = 
self.input_file.readline()<BR>            
print line()+". 
line_==|"+line_.strip()+"|"<BR>            
self.total_chars += 
len(line_)<BR>            
print line()+". line length:",len(line_),"; file 
pointer:",self.input_file.tell(),<BR>            
print "; total chars:",self.total_chars,"; diff:",self.input_file.tell() - 
self.total_chars<BR>            
if not 
line_:<BR>                
break<BR>            
yield line_.strip()</FONT></P>
<P><BR><FONT face="Courier New" size=1>if __name__ == "__main__":</FONT></P>
<P><FONT face="Courier New" size=1>    filename = 
sys.argv[1]<BR>    log_stream = 
LogStream(filename)<BR>    
log_stream.input_file.seek(0)<BR>    log_stream.total_chars = 
0<BR>    line_generator = 
log_stream.line_generator()<BR>    for i in 
range(8):<BR>        line_ = 
line_generator.next() <BR></FONT></P></FONT></BODY></HTML>