为什么以下工作(Python 2.5.2)?为什么我不能继承datetime.date?
>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 3 arguments (1 given)
我想创建一个类,简直就像datetime.date
,但有不同的__init__
功能。显然我的功能永远不会被调用。相反,原来的datetime.date.__init__
被调用并失败,因为它需要3个参数,而我正在传入一个参数。
这是怎么回事?这是一个线索?
>>> datetime.date.__init__
<slot wrapper '__init__' of 'object' objects>
谢谢!
另请参阅http://stackoverflow.com/questions/309 129 /为什么我不能继承dict和异常在python – hop 2008-12-29 23:16:29