0

there is a way to pass a value or a variable from a class to another class without having to pass through the main function

I'm using python

1
  • 1
    You rarely pass data from class to class. You usually pass data from object to object. One object can have a reference to another object. Can you provide a small code sample that shows what you are trying to do? Commented Sep 30, 2011 at 12:46

1 Answer 1

1

well, of course you can access other objects attributes in methods of a specific object. e.g:

class A(object):
    def method(self, other):
         other.somevar = 5

class B(object):
    pass

def main():
    a = A()
    b = B()

    b.somevar = "Hello World"
    a.method(b)
    print(b.somevar) # now prints '5'
Sign up to request clarification or add additional context in comments.

Comments

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.