我想延长日期时间.日期类添加一个名为status
的属性,该属性表示该日期是否为工作日、管理性非工作日、法院关闭日,。。。在
我读过How to extend a class in python?、How to extend Python class init和{a3},但我不太理解,所以我对OOP一无所知。在
>>> import datetime
>>> class Fecha(datetime.date):
def __init__(self, year, month, day, status):
super(Fecha, self).__init__(self, year, month, day)
self.status = status
>>> dia = Fecha(2014, 7, 14, 'laborable')
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
dia = Fecha(2014, 7, 14, 'laborable')
TypeError: function takes at most 3 arguments (4 given)
>>>
问题出在超级通话中
试试这个。在
datetime.date
是一个不可变的类型,这意味着您需要重写^{演示:
^{pr2}$相关问题 更多 >
编程相关推荐