python subclassing: TypeError object.__new__() takes no parameters

末鹿安然 提交于 2019-12-02 14:13:38

问题


Ok I'm stumped again! This should be easy though ;-)

I'm trying to subclass the pytables class tables.IsDefinition, as follows:

import tables

class doc(tables.IsDescription):
    def __init__(self, data):
        self.data = data

And then I try to instantiate it I get an error:

doc('test')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

...<ipython console> in <module>()

TypeError: object.__new__() takes no parameters

This is with Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) and IPython 0.10

What am I doing wrong?


回答1:


In case anyone else lands here, the answer is that IsDescription is a "metaclass". More information can be found on this thread



来源:https://stackoverflow.com/questions/8741463/python-subclassing-typeerror-object-new-takes-no-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!