Python super() 不适用于 Enum 参数
Python super() not work with Enum parameter
我有
的代码
from enum import Enum
EventType = Enum('EventType', ('TIMER_EVENT', 'LOG_EVENT'))
class Event(object):
def __init__(self, type_=None):
self.type_ = type_
class LogEvent(Event):
def __int__(self):
super(LogEvent, self).__init__(EventType.LOG_EVENT)
class TimerEvent(Event):
def __init__(self):
super(TimerEvent, self).__init__(EventType.TIMER_EVENT)
print(LogEvent().type_)
print(TimerEvent().type_)
结果是
None
EventType.TIMER_EVENT
super()
函数在classLogEvent
和TimerEvnet
中几乎相同
但是为什么LogEvent
的super()
功能不起作用?
我的python版本是3.6.4
在 LogEvent
class 中你有 def __int__
而不是 def __init__
。
我有
的代码from enum import Enum
EventType = Enum('EventType', ('TIMER_EVENT', 'LOG_EVENT'))
class Event(object):
def __init__(self, type_=None):
self.type_ = type_
class LogEvent(Event):
def __int__(self):
super(LogEvent, self).__init__(EventType.LOG_EVENT)
class TimerEvent(Event):
def __init__(self):
super(TimerEvent, self).__init__(EventType.TIMER_EVENT)
print(LogEvent().type_)
print(TimerEvent().type_)
结果是
None
EventType.TIMER_EVENT
super()
函数在classLogEvent
和TimerEvnet
但是为什么LogEvent
的super()
功能不起作用?
我的python版本是3.6.4
在 LogEvent
class 中你有 def __int__
而不是 def __init__
。