开发者

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

开发者 https://www.devze.com 2023-04-09 07:46 出处:网络
there is a way to pass a value or a variable from a class to another class without having to pass through 开发者_如何学C the main function

there is a way to pass a value or a variable from a class to another class without having to pass through 开发者_如何学C the main function

I'm using python


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

精彩评论

暂无评论...
验证码 换一张
取 消