?
=?ISO-8859-1?Q?Martin_H=E4cker?=
Hi there,
I just tried to run this code and failed miserably - though I dunno why.
Could any of you please enlighten me why this doesn't work?
Thanks a bunch.
--- snip ---
import unittest
from datetime import datetime
class time (datetime):
def __init__(self, hours=0, minutes=0, seconds=0, microseconds=0):
print "blah"
datetime.__init__(self, 1, 1, 1, hours, \
minutes, seconds, microseconds)
class Test (unittest.TestCase):
def testSmoke(self):
# print time() # bombs, and complains that
# the time ctor needs at least 3 arguments
self.assertEquals(datetime(1,1,1,1,2,3,4),time(1,2,3,4))
if __name__ == '__main__':
unittest.main()
--- snap ---
The reason I want to do this is that I want to work with times but I
want to do arithmetic with them. Therefore I cannot use the provided
time directly.
Now I thought, just overide the ctor of datetime so that year, month and
day are static and everything should work as far as I need it.
That is, it could work - though I seem to be unable to overide the ctor.
Why is that?
cu Martin
I just tried to run this code and failed miserably - though I dunno why.
Could any of you please enlighten me why this doesn't work?
Thanks a bunch.
--- snip ---
import unittest
from datetime import datetime
class time (datetime):
def __init__(self, hours=0, minutes=0, seconds=0, microseconds=0):
print "blah"
datetime.__init__(self, 1, 1, 1, hours, \
minutes, seconds, microseconds)
class Test (unittest.TestCase):
def testSmoke(self):
# print time() # bombs, and complains that
# the time ctor needs at least 3 arguments
self.assertEquals(datetime(1,1,1,1,2,3,4),time(1,2,3,4))
if __name__ == '__main__':
unittest.main()
--- snap ---
The reason I want to do this is that I want to work with times but I
want to do arithmetic with them. Therefore I cannot use the provided
time directly.
Now I thought, just overide the ctor of datetime so that year, month and
day are static and everything should work as far as I need it.
That is, it could work - though I seem to be unable to overide the ctor.
Why is that?
cu Martin