Python论坛  - 讨论区

标题:[python-chinese] [新手问题]我这个程序有点问题,贴出来,请教一下!

2006年12月08日 星期五 13:50

boyeestudio boyee118在gmail.com
星期五 十二月 8 13:50:20 HKT 2006

ÏÂÃæµÄ³ÌÐòµÄ¹¦ÄÜÏ൱ÓÚ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 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年12月12日 星期二 10:54

=?GB2312?B?u8bBiA==?= huangchonggnu在gmail.com
星期二 十二月 12 10:54:37 HKT 2006

ÈôÊÇÖ»¶Á×îºóÒ»ÐУ¬ÊÔÊÔ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 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年12月12日 星期二 11:03

nmweizi nmweizi在163.com
星期二 十二月 12 11:03:46 HKT 2006

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 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年12月12日 星期二 12:39

boyeestudio boyee118在gmail.com
星期二 十二月 12 12:39:25 HKT 2006

ÔÚ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 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号