On 2005-08-01, Rob Conner <[EMAIL PROTECTED]> wrote: > So this is simple, why can't I run the following code? I've tried many > variances of this, but simply cannot inherit from datetime or > datetime.datetime. I get this on line 3. > TypeError: function takes at most 2 arguments (3 given) > > ******************************** > import datetime > _datetime = datetime.datetime > > class MyDateTime(_datetime): > """ > Identical to builtin datetime.datetime, except it accepts > invalid dates and times as input. > """ > _valid = True > > def __init__(self, year, month, day, *args, **kw): > try: > _datetime.__init__(self, year, month, day, *args, **kw) > except _datetime.ValueError: > _valid = False > self.year = year > self.month = month > self.day = day > self.args = args > self.kw = kw > ******************************** >
It helps to post the actual code and error message you are seeing... >>> import datetime >>> class foo(datetime): ... pass ... Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: function takes at most 2 arguments (3 given) >>> class foo(datetime.datetime): ... pass ... >>> d = foo() Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: function takes at least 3 arguments (0 given) >>> d = foo(1, 2, 3) >>> d foo(1, 2, 3, 0, 0) >>> datetime.datetime(1, 2, 3) datetime.datetime(1, 2, 3, 0, 0) My guess is that the code you posted is not really the code you were runnning. -- http://mail.python.org/mailman/listinfo/python-list