python/pygame, pass input from a class to another class

前端 未结 1 1367
不知归路
不知归路 2021-01-27 18:08

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条回答
  • 2021-01-27 18:28

    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'
    
    0 讨论(0)
提交回复
热议问题