调用模块的访问名称空间 [英] Access namespace of calling module

查看:67
本文介绍了调用模块的访问名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是通常不应该做的事情,并且我知道这样做的原因.但是,我在一个类中创建了一个调试函数,该函数应该显示一些有关调用它的模块的信息.

I know this is something one normally should not do, and I know the reasons for it. However, I am making a debugging function within a class that should display some information about the module that called it.

我需要知道如何在名称空间中上一层,以找到一个变量,该变量应始终存在于既调用此模块又需要此函数的程序中.

I need to know how to go up one level in the name space to find a variable that should always exist in a program that both calls this module and needs this function.

我知道可以使用以下方法获得主名称空间:

I know one can get the main name space with:

    import __main__

但是我猜测这包括从第一个启动的模块开始的所有内容,而我只想要一个称为该模块的东西.

But I'm guessing that this includes everything from the very first launched module onward, and I just want the one that called this one.

推荐答案

尝试使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆