How to initialize an inherited object with either the 'usual' (keyword) arguments or an instance of the parent

前端 未结 1 1973
离开以前
离开以前 2021-01-26 11:06

I\'d like to extend datetime\'s timedelta class with a modulo operation. I\'d also like to be able to initialize the resulting TimeDelta c

1条回答
  •  情话喂你
    2021-01-26 11:43

    Python doesn't go into your __init__ at all. The timedelta class defines __new__, as you can see in the source code, and the error occurs there - which is why you don't see your code in the traceback.

    (Also note that self = timedeltas[0] doesn't do anything at all other than rebind the local name, so your code wouldn't work even if you got around the init problem.)

    0 讨论(0)
提交回复
热议问题