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

你。 提交于 2021-02-05 09:31:02

问题


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:


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'


来源:https://stackoverflow.com/questions/7610531/python-pygame-pass-input-from-a-class-to-another-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!