ygg*_*dra 1 python oop methods class python-2.7
我有一个关于python类的快速问题.以下是设置:我有一个类作为"mastermind"类,其中包含其他类的各种实例.现在这些类需要调用其他类的方法,但我不知道该怎么做.例如:
class mastermind(object):
def __init__(self):
self.hand = hand()
def iNeedToCallThisMethod(self, funzies):
print funzies
class hand(object):
def __init(self):
pass #here should be a call to the mastermind instance's method
example = mastermind()
Run Code Online (Sandbox Code Playgroud)
希望你们可以帮助我,我的大脑正在蒸!非常感谢!
如果要调用mastermind的方法,则需要引用它.
例如
class mastermind(object):
def __init__(self):
self.hand = hand(self)
def iNeedToCallThisMethod(self, funzies):
print funzies
class hand(object):
def __init__(self, mastermind)
mastermind.iNeedToCallThisMethod('funzies')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14560 次 |
最近记录: |