Hi everyone,
I'd like to create a child class to the date class in the datetime module and, apart from adding some new methods to it, I'd like my child class to be initializable through different argument arrangements.
For example, beyond the (year, month, day) initialization arguments of the parent, I'd like the child class to be also initializable through a string, say, '1Jan2009', where the __init__ () method of the child is called with *args and depending on the arguments it resolves what (year, month, day) list it should use to initialize the parent, something like:
class DatePlus(date):
def __init__(self, *args):
if len(args) == 3:
(y, m, d) = args
elif len(args) == 1 and type(args[0]) == type(''):
(y, m, d) = self.translate_string(self, arg[0])
date.__init__(self, y, m, d)
However, I can't seem to be able to initialize the child class with a single argument; I get a TypeError that 3 arguments are required, 1 given.
Is there a way to accomplish what I'm trying to do or should the child class always be called with the same argument list structure as the parent?
Many thanks and have a happy new year.