how to remove the blank lines?

boyeestudio boyee118 at gmail.com
Fri Dec 8 03:14:57 EST 2006


The following program have the same function as the linux's command:tail -f
logfile.log
But it print a lot of blank lines while showing on the stdout.
How to fix this problem and let it go ahead always
showing the end line as the log file's increasing.

#tail.py:

import os
import sys

class Tail:
    def __init__(self,inputstream):
        self.inputstream=inputstream

    def tail(self):
        self.inputstream.seek(0,2)     #??Maybe this is where I'll need
fixed,But I don't know how to....
        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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061208/9985ae0f/attachment.html>


More information about the Python-list mailing list