我被Python中的这种继承行为难住了。据我所知,超级类构造函数被正确调用,尽管语法从2.7到3.5有所不同。Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>>
>>> import pandas as pd
>>> class MyTimestamp(pd.Timestamp):
... def __init__(self, arg, **kwargs):
... super(MyTimestamp, self).__init__(arg, **kwargs)
...
>>> a=MyTimestamp(1312342152423, unit='us')
>>> a
Timestamp('1970-01-16 04:32:22.152423')
使用Python3.5.1解释器,我得到了以下结果,两者都安装了相同版本的Pandas(0.18.0),但我相信这更多的是一个Python继承的东西。Python 3.5.1 |Continuum Analytics, Inc.| (default, Dec 7 2015, 11:16:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pandas as pd
>>> class MyTimestamp(pd.Timestamp):
... def __init__(self, arg, **kwargs):
... super().__init__(arg, **kwargs)
...
>>> a=MyTimestamp(1312342152423, unit='us')
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in __init__
TypeError: object.__init__() takes no parameters
MyTimestamp的mro指定:(,
,
,
,
,
)
因此object不是解析顺序中的下一个类。这个错误是从哪里来的,也许更重要的是,我做错了什么,我可以改变来解决这个问题?