Python: Unbound __init __ () method from import.class

I am trying to subclass a class from another python script.

I did the following when subclassing from a single file, and it works.

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

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

But as soon as I add to the inheritance from another file ..

superWidget.py

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

I get an error message:

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

Is there a way to subclass a class from another package that works?

.

And out of curiosity, what kind of deal? Essentially it looks identical to me. I can call the class from another file using widge.widget (), so the method seems to be set. And I can subclass when the class is in the same file, referencing the class in the declaration. What is the use of a class from import in an ad that breaks? Why does he see himself as the correct method in the same file, but does he see himself as an unrelated method when importing?

, - ( , .

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
+4
1

superWidget.py SuperWidget super

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

Source: https://habr.com/ru/post/1626871/


All Articles