超级祖父母方法 [英] grandparent method with super
问题描述
我有一个类结构如下,我想从Dm调用
方法Am()
A级(对象):
def m(个体经营):
B级(A):
def m(个体经营):
C级(A):
def m(个体经营):
D级(B,C):
def m(个体经营):
#用超级电话叫我?
我读过 http://www.python.org/download/releases/2.2/descrintro/ 但
我仍然被卡住了。
提前致谢
Martin
4月5日下午3:19,Martin Manns< mma ... @ gmx.dewrote:
我有一个类结构如下,我想从Dm调用
方法Am()
A级(对象):
def m(个体经营):
B级(A):
def m(个体经营):
C级(A):
def m(个体经营):
D级(B,C):
def m(个体经营):
#超级召唤Am?
>
我已经阅读了:http://www.python.org/download/releases/2.2/descrintro/but
我仍然被卡住了。
提前致谢
Martin
我不确定这是不是你想要的,但它''我最好的猜测:
A级(对象):
def m(self):
print" I' '原来的'
B级(A):
def m(个体经营):
打印''B class here''
C级(A):
def m(个体经营):
打印''C class here''
级D(B,C):
def m(个体经营):
x = A()
xm()
temp = D()
temp.m()
Mike
很确定你能做到这一点:
A级(对象):
def m(个体经营):
B级(A):
def m(个体经营):
C级(A):
def m(个体经营):
D级( B,C):
def m(个体经营):
Am(个体)
我不认为你想要在这种情况下尝试使用super()。
-jdc
-----原始消息-----
来自:py ********************************* @ python.org
[mailto:py ********************************* @ python。组织代表马丁
Manns
发送时间:2007年4月5日星期四下午4:20
收件人: py ********* @ python.org
主题:超级祖父母方法
我的课程结构如下,我想调用方法
Am ()来自Dm
A级(对象):
def m(个体经营):
B级(A):
def m(个体经营):
C级(A):
def m(个体经营):
D级(B,C):
def m(个体经营):
#超级打电话给我?
我有阅读 http://www.python.org/download/releases/ 2.2 / descrintro / 但是我还是
仍然卡住了。
提前致谢
Martin
-
http: / /mail.python.org/mailman/listinfo/python-list
2007年4月5日星期四16:33:37 -0400
" John Clark" < cl ***** @ mac.comwrote:
很确定你能做到这一点:
A级(对象):
def m(个体经营):
B级(A):
def m(个体经营):
class C(A):
def m(self):
class D(B,C):
def m (个体经营):
Am(个体)
在这种情况下,我不认为你想尝试使用super()。
这样可行,但是当我用其他东西替换A时,我不再获得
祖父母而不改变所有方法调用。基本上,我是
想在D的第一个祖父母中调用m方法。
Martin
Hi,
I have a class structure as follows and I would like to invoke the
method A.m() from D.m
class A(object):
def m(self):
class B(A):
def m(self):
class C(A):
def m(self):
class D(B,C):
def m(self):
# Call A.m with super?
I have read http://www.python.org/download/releases/2.2/descrintro/ but
I am still stuck.
Thanks in advance
Martin
On Apr 5, 3:19 pm, Martin Manns <mma...@gmx.dewrote:Hi,
I have a class structure as follows and I would like to invoke the
method A.m() from D.m
class A(object):
def m(self):
class B(A):
def m(self):
class C(A):
def m(self):
class D(B,C):
def m(self):
# Call A.m with super?
I have readhttp://www.python.org/download/releases/2.2/descrintro/but
I am still stuck.
Thanks in advance
MartinI''m not sure if this is what you want, but it''s my best guess:
class A(object):
def m(self):
print "I''m the original"
class B(A):
def m(self):
print ''B class here''
class C(A):
def m(self):
print ''C class here''
class D(B,C):
def m(self):
x = A()
x.m()
temp = D()
temp.m()
Mike
Pretty sure you can do this:
class A(object):
def m(self):
class B(A):
def m(self):
class C(A):
def m(self):
class D(B,C):
def m(self):
A.m(self)
I don''t think you want to try to use super() in this case.
-jdc
-----Original Message-----
From: py*********************************@python.org
[mailto:py*********************************@python. org] On Behalf Of Martin
Manns
Sent: Thursday, April 05, 2007 4:20 PM
To: py*********@python.org
Subject: grandparent method with super
Hi,
I have a class structure as follows and I would like to invoke the method
A.m() from D.m
class A(object):
def m(self):
class B(A):
def m(self):
class C(A):
def m(self):
class D(B,C):
def m(self):
# Call A.m with super?
I have read http://www.python.org/download/releases/2.2/descrintro/ but I am
still stuck.
Thanks in advance
Martin
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 5 Apr 2007 16:33:37 -0400
"John Clark" <cl*****@mac.comwrote:
Pretty sure you can do this:
class A(object):
def m(self):
class B(A):
def m(self):
class C(A):
def m(self):
class D(B,C):
def m(self):
A.m(self)
I don''t think you want to try to use super() in this case.That works, but when I replace A with something else, I do not get the
grandparent anymore without changing all the method calls. Basically, I
would like to call the method m in the first grandparent of D.
Martin
这篇关于超级祖父母方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!