Hey everyone, this should be simple, but I keep running into errors so help is greatly appreciated.

I have a large class, call it class A, which has several methods. Most of these methods modify data.

ClassA()
def __init(X,Y,Z)
...
..

def data_mod1():
...

def data_mod2():
...

I'm dealing with a large GUI program, which has several connected buttons. Therefore, I have another class to do nothing but handle button operations. Most of these operations are stylistic (changing colors and names). For example:

class Button_manager()

def color_style1():
....

def attribute_style1():
....

Here is the issue. At some point, it is advantageous to change the data at the level of the button_manager. Therefore, I need to borrow a method from ClassA. For example, the method

def data_mod1():

Ought to be callable from the button_manager or ClassA. I can't for the life of me get this to work though. I've tried following example on inheritance and stuff, but because the Button_Manager class is called through ClassA, it seems to give me issues. Basically, how do I load Button_Manager to share this method.

Edited 5 Years Ago by hughesadam_87: n/a

You are calling the __init__ of inherited class in beginning of child __init__ , aren't you? Could you post restricted example with only the problem behaviour?

You are calling the __init__ of inherited class in beginning of child __init__ , aren't you? Could you post restricted example with only the problem behaviour?

Thanks tony. I don't quite understand what that means. Can you post a quick metacode example, and then I'll put it into my code and post the restricted example? Sorry for my idiocy.

The easiest solution is to have both Class A and Button_Manager inherit a common superclass which holds their common methods

class Common(object):
    def data_mod1(self):
        ...

class A(Common):
    ...

class Button_Manager(Common):
    ...

Edited 5 Years Ago by Gribouillis: n/a

I am newbie myself in this stuff having grown more with procedural and functional structured/modular programming, but I contrived this example, let the experts correct me:

class Funny(object):
    def __init__(self, content):
        self.content = content

    def justify(self, width=40):
        return str(self).rjust(width)

    def __str__(self):
        return ' '.join(str(c) for c in self.content)

class More_funny(Funny):
    def __init__(self, *args, **kwargs):
        Funny.__init__(self, args)
        self.times = kwargs['times']

    def many_times(self):
        return self.times * self.justify()

    def center(self, width=60):
        return str(self).center(width)


donald = Funny(('Donald', 43534))
duck = More_funny('Duck', 313, times = 13)

print(donald.justify())
print(duck)
print(duck.justify(20))
print(duck.center(60))
print(str(duck.center(80)).upper())
print(duck.many_times())

Edited 5 Years Ago by pyTony: n/a

Thanks a lot guys. Let me play with the suggestions you've posted and see if I can get my stuff straightened out.

Thanks for the help guys. The method that Griboullis suggested seems to work with my code as it is. The other method doesn't work, but it's because I am using Tkinter and all of the pre-defined control variables produce this error:

Exception _tkinter.TclError: 'can\'t unset "PY_VAR1386": no such variable' in <bound method IntVar.__del__ of <Tkinter.IntVar instance at 0xc297e2c>> ignored

This is probably my fault, since I don't have a strong grasp on inheritance so I don't really know what I'm doing. Thanks both of you for your help.

This question has already been answered. Start a new discussion instead.