Overloading ctor doesn't work?

Martin Häcker dwt23 at hotmail.com
Thu Jan 20 19:23:35 CET 2005

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

if __name__ == '__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

Reach me at spamfaenger (at) gmx (dot) net

More information about the Python-list mailing list