Python:来自 import.class 的未绑定方法 __init__()

Python: Unbound method __init__() from import.class

我正在尝试从另一个 python 脚本中继承 class 一个 class。

我在从同一文件中进行子classing 时执行了以下操作,并且有效。

widge.py
    class widget(object):
        def __init__(self,bob):
            #do something

    class evenWidgetier(widget):
        def __init__(self, bob):
            widget.__init__(self,bob)
            #do something

但是一旦我从另一个文件中添加继承..

superWidget.py

    import widge
    class superWidgety(widge.evenWidgetier):
        def __init__(self, bob):
            widge.widget.__init__(self,bob)
            #do something

我收到一个错误:

unbound method __init__() must be called with widget instance as first argument

有没有办法从另一个有效的包中子class一个class?

.

出于好奇,这是怎么回事? 实质上,这看起来与我相同。我可以使用 widge.widget() 从另一个文件调用 class,因此该方法似乎已建立。当 class 在同一文件中时,我可以通过在声明中引用 class 来 subclass 。在中断的声明中使用来自导入的 class 是什么意思?为什么它在同一个文件中将自己视为正确的方法,但在导入时却将自己视为未绑定的方法?

具体来说,我的代码是这样的(剥离不应该影响它的部分。

Attributor.py
    class Tracker(object):
        def __init__(self, nodeName=None, dag=None):
            #Tracking stuff

    class Transform(Tracker):
        #Does stuff with inherited class

timeline_tab.py
    import Attributor as attr

    class timeline(attr.Transform):
        #some vars
        def __init__(self, nodeName=None):
            attr.Transform.__init__(self,nodeName=nodeName)
            #Additional init stuff, but doesn't happen because error on previous line

superWidget.py 中将 SuperWidget 更改为使用 super

    import widge
    class superWidgety(widge.evenWidgetier):
        def __init__(self, bob):
            super(SuperWidget,self).__init__(bob)
            #do something