2006年12月12日 星期二 09:35
boyeestudio,您好!
print 会自动添加回车换行,而实际上读入的line可能只有半行。
======== 2006-12-08 13:50:00 您在来信中写道: ========
下面的程序的功能相当于linux下的命令:tail -f logfile.log
但是显示时,打印很多空行,不知道file.seek()如何定位最后一行(这一行的字节数是个变数,所以不好定位),哪位指点一下!谢谢了。
import os
import sys
class Tail:
def __init__(self,inputstream):
self.inputstream=inputstream
def tail(self):
self.inputstream.seek(0,2) #??
line=self.inputstream.readline().strip()
print line
if __name__=="__main__":
if len(sys.argv)<=1:
print "You must type a log file name"
sys.exit()
arg=file(sys.argv[1],'r+')
while(arg):
try:
t=Tail(arg)
t.tail()
except KeyboardInterrupt:
arg.close()
print "File closed"
= = = = = = = = = = = = = = = = = = = = = =
致
礼!
Jin Qing
jinq0123在163.com
2006-12-12
Zeuux © 2025
京ICP备05028076号