-1

I want to use a variable from class A for some computation in class B. I,m not sure that I use the self.out from the class A in class B appropriately?

Class A:

class A(nn.Module):
    def __init__(self):
        super(A, self).__init__()
        
        self.out = func()

Class B:

class B(nn.Module):
    def __init__(self):
        super(A, self).__init__()
        
        self.result = function_1() + A.self.out

1 Answer 1

2

Maybe this is what you need. I made a small example of what I understood. These "prints" were placed to improve the understanding that Class "C" can fetch any function or variable from the other parent classes.

class A():
    def __init__(self):
        variable = None
    def test(self, number):
        return f'another class {number}'

class B():
    def __init__(self):
        self.data = None
        self.out = self.print_data(5)
    def print_data(self, number):
        return number
    def print_elem(self):
        return self.data
class C(A, B):
    def __init__(self):
          super().__init__()
        
c = C()

print(c.print_data(8))
print(c.out)
c.data = 100
print(c.print_elem())

print(c.test(3))

Sign up to request clarification or add additional context in comments.

1 Comment

@dtr43 If my answer has resolved your issue, I ask that you mark it as resolved or "ACCEPT", so that it will be closed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.