Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't call this method from an instance of <code>MyClass</code>, You call it from an instance of <code>MySubclass</code>. The problem is that you're probably getting a <code>TypeError</code> since the argument (self) that you're passing to <code>firstFunc</code> is the wrong type (<code>MyClass</code> instead of <code>MySubClass</code>). The solution is to restructure your code so this doesn't happen. At least, I assume that's the problem (when I tried you code, I got all sorts of import errors). Here's the code that I tried (which I assume illustrates the problem you're describing):</p> <pre><code>class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = "foo" self.attr2 = "bar" def test(self): return MySubClass.firstFunc(self, 2, 2) class MySubClass(MyClass): def firstFunc(self, a, b): c = a + b d = self.secondFunc(c) #removed self from parameter list return d def secondFunc(self, c): d = c / 2 return d a=MyClass() b=MySubClass() print (b.test()) #this works because b is the right type to pass to first/second func a.test() #This doesn't work because a is the wrong type. </code></pre> <p>Notice that it doesn't really make sense to have <code>test</code> as a method of <code>MyClass</code> because you <strong>can't</strong> use it from there anyway. You might as well just move <code>test</code> onto <code>MySubClass</code>.</p> <p>Also, as others have noted, <code>self.secondfunc(self,c)</code> is also very strange. This is basically equivalent to <code>MySubClass.secondfunc(self,self,c)</code> which has the wrong number of arguments, as you're passing <code>self</code> twice.</p> <p>This works:</p> <pre><code>class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = "foo" self.attr2 = "bar" def test(self): return firstFunc(self, 2, 2) def firstFunc(self, a, b): c = a + b d = secondFunc(self,c) #self from in front of function, now in parameter list return d def secondFunc(self, c): d = c / 2 return d class MySubClass(MyClass): firstFunc=firstFunc secondFunc=secondFunc a=MyClass() b=MySubClass() print (b.test()) print (a.test()) </code></pre> <p>But I highly recommend restructuring your code.</p>
 

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