在python中在模块之间传递对象的最合适方法是什么?

时间:2014-03-18 17:43:59

标签: python object import module

我必须从另一个模块访问模块中的对象:

module_1.py:

import module_2

class A():
    def __init__():
         do_sth()

class B():
    def __init__():
         do_sth()
         self.x = some_object()
         do_sth_else(x)

    def show():
        show_gui()

def start():
    y = B()
    y.show()

if __name__ == "__main__":
    start()

module_2.py:

def run_it(arg):
    run_run_run()

我需要来自self.x的{​​{1}}对象,以便我可以将其作为参数传递给module_1中的run_it()函数。请注意,module_2还会导入module_1

是否有传统的方法来访问其他模块中的对象?

0 个答案:

没有答案