[Q] override __init__() method of classes implemented in C

Makoto Kuwata kwa at kuwata-lab.com
Mon Jun 30 03:45:34 EDT 2014


Is it impossible to override __init__() method of classes
implemented in C (such as datetime.datetime) ?


example.py:

from datetime import datetime
 class Foo(datetime):
    def __init__(self):
        pass
 obj = Foo()


Result (Python 2.7.7 and 3.4.1):

Traceback (most recent call last):
  File "hoge.py", line 7, in <module>
    obj = Foo()
TypeError: Required argument 'year' (pos 1) not found


It seems to be failed to override datetime.__init__() in subclass.


--
regards,
makoto kuwata
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140630/4085a9f1/attachment.html>


More information about the Python-list mailing list