Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I call a method of a subclass from a superclass method?
    primarykey
    data
    text
    <p>Suppose I have this class:</p> <pre><code>class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = "foo" self.attr2 = "bar" def test(): from subclassfile import MySubClass MySubClass.firstFunc(self, 2, 2) test() </code></pre> <p>And this subclass in other file:</p> <pre><code>from classfile import MyClass class MySubclass(MyClass): def firstFunc(self, a, b): c = a + b d = self.secondFunc(self, c) return d def secondFunc(self, c): d = c / 2 return d </code></pre> <p>This is a silly example, but represents exactly what I'm trying to do. I want to call the second function from the subclass inside the first function. But when I do that it returns an error that says that MyClass doesn't have such function. So I suppose that I shouldn't be using the <code>self</code> in front of the function name when I call it. But when I don't it raises an error too.</p> <p>So my question is: How do I access this second function inside the first function of a subclass?</p> <p>EDIT:</p> <p>Thank you all for the help. I'll explain better what I'm trying to do while I guess that my implementation is really bad in the code. MyClass is the main Class of the code, where all the widgets and main functions are. There is also a button on this Class that is binded with the "test" function. So when the button is pressed the whole thing should work. The MySubClass file is an auxiliary module that exports data to some file. The firstFunc is the main function in this module that handles with all the data while secondFunc just builds the template of the file. So I call this secondFunc inside the firstFunc so that the template is loaded and then the data is written in the file. I made this MySubClass inherited from the MyClass so that it could have access to the database and other variables directly from the MyClass.</p> <p>So I suppose that I could do this otherway. But I'm not really experienced with this kind of implementation. Also, sorry for my bad english.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload