2006年12月08日 星期五 13:50
ÏÂÃæµÄ³ÌÐòµÄ¹¦ÄÜÏ൱ÓÚ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" -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061208/c71b06c3/attachment.html
2006年12月12日 星期二 10:54
ÈôÊÇÖ»¶Á×îºóÒ»ÐУ¬ÊÔÊÔreadlines() lst=self.inputstream.readlines() print lst[-1] ÔÚ06-12-8£¬boyeestudio <boyee118在gmail.com> дµÀ£º > > ÏÂÃæµÄ³ÌÐòµÄ¹¦ÄÜÏ൱ÓÚ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" > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061212/3976b648/attachment.htm
2006年12月12日 星期二 11:03
python-chinese£¬ÄãºÃ ÕâÑù¿ÉÒÔÁË¡£ #!/usr/bin/env python import os import sys import time class Tail: def __init__(self,inputstream): self.inputstream=inputstream self.inputstream.seek(0,2) def tail(self): #self.tell = self.inputstream.tell() line=self.inputstream.readline().strip() if line: 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]) t = Tail(arg) while(arg): try: time.sleep(2) t.tail() except KeyboardInterrupt: arg.close() print "File closed" sys.exit(1) nmweizi£¬nmweizi在163.com 2006-12-12 ----- Original Message ----- From: »ÆÁ To: python-chinese Sent: 2006-12-12, 10:54:37 Subject: Re: [python-chinese]£ÛÐÂÊÖÎÊÌâ£ÝÎÒÕâ¸ö³ÌÐòÓеãÎÊÌ⣬Ìù³öÀ´£¬Çë½Ìһϣ¡ ÈôÊÇÖ»¶Á×îºóÒ»ÐУ¬ÊÔÊÔreadlines() lst=self.inputstream.readlines() print lst[-1] ÔÚ06-12-8£¬boyeestudio <boyee118在gmail.com > дµÀ£º ÏÂÃæµÄ³ÌÐòµÄ¹¦ÄÜÏ൱ÓÚ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" _______________________________________________ python-chinese Post: send python-chinese在lists.python.cn Subscribe: send subscribe to python-chinese-request在lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061212/49ed8b89/attachment.html
2006年12月12日 星期二 12:39
ÔÚ06-12-12£¬nmweizi <nmweizi在163.com> дµÀ£º > > python-chinese£¬ÄãºÃ > ÕâÑù¿ÉÒÔÁË¡£ > > #!/usr/bin/env python > import os > import sys > import time > class Tail: > def __init__(self,inputstream): > self.inputstream=inputstream > self.inputstream.seek(0,2) > > def tail(self): > #self.tell = self.inputstream.tell() > line=self.inputstream.readline().strip() > if line: > 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]) > t = Tail(arg) > while(arg): > try: > time.sleep(2) > t.tail() > except KeyboardInterrupt: > arg.close() > print "File closed" > sys.exit(1) > ллnmweizi£¡ nmweizi£¬nmweizi在163.com<%3C%21--AID_FROMADDRESS_BEGIN--%3Enmweizi在163.com%3C%21--AID_FROMADDRESS_END--%3E> > 2006-12-12 > > ----- Original Message ----- > *From: *»ÆÁ <huangchonggnu在gmail.com> > *To: *python-chinese <python-chinese在lists.python.cn> > *Sent: *2006-12-12, 10:54:37 > *Subject: *Re: [python-chinese]£ÛÐÂÊÖÎÊÌâ£ÝÎÒÕâ¸ö³ÌÐòÓеãÎÊÌ⣬Ìù³öÀ´£¬Çë½Ìһϣ¡ > > ÈôÊÇÖ»¶Á×îºóÒ»ÐУ¬ÊÔÊÔreadlines() > lst=self.inputstream.readlines() > print lst[-1] > > > ÔÚ06-12-8£¬boyeestudio <boyee118在gmail.com > дµÀ£º > > > > ÏÂÃæµÄ³ÌÐòµÄ¹¦ÄÜÏ൱ÓÚ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" > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061212/b29cd4fa/attachment-0001.html
Zeuux © 2025
京ICP备05028076号