我法语对不起我的英语,
我尝试将我的 c# 代码转换为 python,但我遇到了这个问题。
我在这个地址找到了代码 python 的类事件:http ://www.voidspace.org.uk/python/weblog/arch_d7_2007_02_03.shtml#e616
我会尝试在我的 python 代码中实现这个。
我的 C# 代码:
// using
...
public abstract class SocketBase
{
public delegate void _onConnected();
public event _onConnected OnConnected;
public SocketBase()
{
...
}
public void TestEvent()
{
OnConnected();
}
}
public class SocketClient : SocketBase
{
public SocketClient()
{
base.OnConnected += Connected;
base.TestEvent();
}
public void Connected()
{
// print
}
}
还有我的python代码:
from EventHook import *
class SocketBase(object):
def __init__(self):
self.onConnected = EventHook()
def TestEvent(self)
self.onConnected.fire()
class SocketClient(SocketBase):
def __init__(self):
SocketBase.__init__(self)
# How to access at the base class event from the child class ?
SocketBase.onConnected += self.Connected
SocketBase.TestEvent(self)
def Connected(self):
print "Connected :) !"
你能帮我吗 ?
昆汀。