0

I'm trying to create a middle class that can execute the same function in two classes that have the same methods, passing the args and kwargs.

class B:
    def random_func(self, i, j, test=None):
        print(2)
        
class A:
    def random_func(self, i, j, test=None):
        print(1)

class MiddleClass:
    a = A() 
    b = B()
    def __getattribute__(self, attr, *args?, **kwargs?):
        # How Do I get the *args, **kwargs?
        self.a.attr(*args, **kwargs)
        self.b.attr(*args, **kwargs)
        return something_callable?
    
m = MiddleClass()
m.random_func(1, 3, test="hello")

Thank you!

Mario
  • 76
  • 3
  • 1
    It's really not clear what you want. What is `doit()`? What do you expect it to `do`? – Mark Jul 15 '20 at 06:00
  • I updated the question. I basically want to execute the same function on two different classes without duplicated the call. Meaning, I don't want to `a.random_func()` and `b.random_func()`, but `m.random_func()`. It should apply for any function that belongs to both classes. Thank you! – Mario Jul 15 '20 at 06:17
  • I answered [a similar question](https://stackoverflow.com/questions/62648826/dispatch-a-function-call-to-a-collection-of-objects/62650173) recently. – Dennis Sparrow Jul 15 '20 at 06:27

0 Answers0