Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:04:45+00:00 2026-06-05T23:04:45+00:00

Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2

  • 0

Suppose I have this class:

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()

And this subclass in other file:

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

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 self in front of the function name when I call it. But when I don’t it raises an error too.

So my question is:
How do I access this second function inside the first function of a subclass?

EDIT:

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:04:46+00:00Added an answer on June 5, 2026 at 11:04 pm

    You don’t call this method from an instance of MyClass, You call it from an instance of MySubclass. The problem is that you’re probably getting a TypeError since the argument (self) that you’re passing to firstFunc is the wrong type (MyClass instead of MySubClass). 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):

    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.
    

    Notice that it doesn’t really make sense to have test as a method of MyClass because you can’t use it from there anyway. You might as well just move test onto MySubClass.

    Also, as others have noted, self.secondfunc(self,c) is also very strange. This is basically equivalent to MySubClass.secondfunc(self,self,c) which has the wrong number of arguments, as you’re passing self twice.

    This works:

    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())
    

    But I highly recommend restructuring your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have something like this: class intlist: def __init__(self,l = []): self.l =
Let's suppose I have this object: [Serializable] public class MyClass { public int Age
I have a class: class MyClass: def __init__(self, foo): if foo != 1: raise
Suppose you have a simple class like this: class foo{ private: int* mData; int
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have a class like this: function myClass(q) { this.someFunction = function(e) {
Suppose, i have class, define('property', 'test'); class myClass { public $test; } $obj=new myClass;
The question is easy, suppose I have: class MyClass { object myObj1 object myObj2
Suppose I have a class like this: class MyClass { private: vector<MyOtherClass> myMember; public:
Suppose I have a simple python class definition in a file myClass.py class Test:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.