# -*- coding: latin-1 -*-


""" I subclass datetime and timedelta

>>> dt = myDatetime(1970,1,1)
>>> type(dt)
<class 'dtime.myDatetime'>

>>> td = myTimedelta(hours=1)
>>> type(td)
<class 'dtime.myTimedelta'>

But when I do arithmetic with these classes, they return datetime and timedelta,
where I want them to return myDatetime and myTimedelta


>>> new_time = dt + td
>>> new_time
datetime.datetime(1970, 1, 1, 1, 0)

>>> type(new_time)
<type 'datetime.datetime'>

So I wondered if there was a simlpler way to coerce the result into my desired
types rather than overwriting the __add__, __sub__ etc. methods?


"""

from datetime import datetime, timedelta

class myDatetime(datetime):
    pass

class myTimedelta(timedelta):
    pass


if __name__ == "__main__":

    import os.path, doctest, dtime
    # import and test this file
    doctest.testmod(dtime)




--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to