在Python中,如何从导入的模块访问主模块的名称空间? [英] In Python, how can I access the namespace of the main module from an imported module?
本文介绍了在Python中,如何从导入的模块访问主模块的名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
具体来说,我需要从导入模块的主模块中获取一些对象和全局变量.我知道当父模块想要子模块中的某些特定东西时如何找到这些东西,但我不知道该如何去做.
Specifically, I need to get at some objects and globals from the main module in an imported module. I know how to find those things when the parent module wants some particular thing from a child module, but I can't figure out how to go in the other direction.
推荐答案
import __main__
但是不要这样做.
这篇关于在Python中,如何从导入的模块访问主模块的名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文