inheriting from datetime

Rob Conner rtconner at gmail.com
Mon Aug 1 16:51:12 EDT 2005


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
********************************




More information about the Python-list mailing list