2004年05月20日 星期四 14:22
An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20040520/592ecf1a/attachment.html -------------- next part -------------- _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese
2004年05月20日 星期四 14:35
liux at gdcn.com,您好! 谢谢各位了。 ======== 2004-05-20 14:22:18 您在来信中写道: ======== class test: def __init__(self): self.a=5 self.b=6 #这个值你就没有返回,怎么能指望子类也正确呢? def add(self): return self.a+self.b class test1(test): def __init__(self): test.__init__(self) self.c=10 def add1(self): return test.add(self)+self.c ----- 原邮件 ----- 从: "info at xichen.com" <info at xichen.com> 日期: 星期四, 五月 20日, 2004 下午2:06 主题: Re: Re: [python-chinese] python中继承的问题 > Frank Zheng,您好! > > 按照你的办法 > class test: > def __init__(self): > self.a=5 > self.b=6 > def add(self): > self.a+self.b > > > class test1(test): > def __init__(self): > test.__init__(self) > self.c=10 > def add1(self): > return test.add(self)+self.c > > p=test1() > print p.a > print p.b > print p.c > print p.add1() > > 这样的代码是错误的。 > > ======= 2004-05-20 14:07:01 您在来信中写道:======= > > > class test: > > def __init__(self): > > self.a=5 > > self.b=6 > > def add(self): > > print self.a+self.b > > return self.a+self.b > > > > > > class test1(test): > > def __init__(self): > > test.__init__(self) > > self.c=10 > > def add1(self): > > return test.add(self) > > > >python里面函数不用明确声明是否有返回值,有的话在函数定义里面return就行了 > > > >----- Original Message ----- > >From: <info at xichen.com> > >To: "python-chinese" <python-chinese at lists.python.cn> > >Sent: Thursday, May 20, 2004 1:17 PM > >Subject: [python-chinese] python中继承的问题 > > > > > >> python-chinese,您好! > >> 在刘鑫的帮助下,我解决了继承的问题,但是用什么方法才能让test的add方法的值和test1的add1的运算值相加呢?谢谢大家了。 > >> class test: > >> def __init__(self): > >> self.a=5 > >> self.b=6 > >> def add(self): > >> print self.a+self.b > >> > >> > >> class test1(test): > >> def __init__(self): > >> test.__init__(self) > >> self.c=10 > >> def add1(self): > >> test.add(self) > >> > >> p=test1() > >> print p.a > >> print p.b > >> print p.c > >> int(p.add())+int(p.add1()) > >> > >> 致 > >> 礼! > >> > >> > >> info > >> info at xichen.com > >> 2004-05-20 > >> > > > > > >------------------------------------------------------------------ > -------------- > > > > > >> _______________________________________________ > >> python-chinese list > >> python-chinese at lists.python.cn > >> http://python.cn/mailman/listinfo/python-chinese > >> > >_______________________________________________ > >python-chinese list > >python-chinese at lists.python.cn > >http://python.cn/mailman/listinfo/python-chinese > > > > = = = = = = = = = = = = = = = = = = = = > > > 致 > 礼! > > > info > info at xichen.com > 2004-05-20 > > = = = = = = = = = = = = = = = = = = = = = = 致 礼! info at xichen.com info at xichen.com 2004-05-20 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20040520/339aafb0/attachment.htm
2004年05月20日 星期四 14:56
python-chinese,您好! 我写的一个多线程程序碰到问题。 我的思路是在一个类中继承其他类的方法和属性,然后加以扩充并满足自己的需要,但是运行程序时出现错误。>>> Traceback (most recent call last): File "C:\Documents and Settings\Administrator\桌面\test.py", line 29, in ? test1.start(x) File "C:\Documents and Settings\Administrator\桌面\test.py", line 24, in start self.threadobj(target=self.t1, args=(x, )).start() TypeError: 'mythread' object is not callable >>> 附上程序,请教各位了。 # -*- coding: cp936 -*- import threading,time import sys class mythread(threading.Thread):#继承线程的类 def __init__(self): threading.Thread.__init__(self)#继承线程的属性 self.running=0#增加一个属性用来判断是否应该结束 class test: def __init__(self): self.threadobj=mythread() self.threadlist=[] def t1(self,count): self.running=1#让线程处于可运行状态 i=0 while i<10 and self.running==1: i+=1 print str(x)+str(i) if i>5:#循环次后,让线程处于中止状态 self.running=0 def start(self,x):#启动线程 self.threadobj(target=self.t1, args=(x, )).start() self.threadlist.append(self.threadobj) test1=test() for x in range(5): test1.start(x) print '共有线程:',threading.activeCount() for k in threading._active.keys(): if threading._active[k] in threadlist: threading._active[k].running=0 del threading._active[k] print '还剩线程: ',threading.activeCount() 致 礼! info info at xichen.com 2004-05-20
Zeuux © 2024
京ICP备05028076号