我有一个听起来像委托问题的问题。我有类似下面的代码:我需要一个委托类?
class foo(object):
def __init__(self,onEvent1="", onEvent2=""):
self.OnEvent1=onEvent1
self.OnEvent1=onEvent2
def aLoop(self):
...
#in case of event1
self.OnEvent1()
...
#in case of event2
self.OnEvent2()
EventType=0
def MyBar1():
print("Event Type1")
EventType=1
def MyBar2():
print("Event Type2")
EventType=2
myFoo=foo(MyBar1,MyBar2)
while True:
myFoo.aLoop()
if (EventType==1):
print ("EventType is 1")
EventType=0
elif (EventType==2):
print ("EventType is 2")
EventType=0
我可以看到print()
回调函数中而不是在while循环的消息的print()
的消息。 变量EventType
不会更改其值。
我能做什么?
好,好!我是个傻瓜... – EffegiWeb 2015-03-03 11:34:51
坦克的帮助,即使在传递参数。 我是新的python编程,我通常在c和Vb.net编写程序。 – EffegiWeb 2015-03-04 17:12:02