find_current_module#
- astropy.utils.introspection.find_current_module(depth=1, finddiff=False)[源代码]#
确定从中调用此函数的模块/包。
此函数有两种模式,由
finddiff
选项。它要么简单地将请求的帧数移到调用堆栈中(如果finddiff
否则它将向上进入调用堆栈,直到到达 not 在指定的集合中。- 参数:
- depth :
int
Python :整型 指定在调用堆栈中返回的时间(索引为0,因此传入0将返回)
astropy.utils.misc
)- finddiff : bool 或
list
Bool或python:列表 如果为False,则返回
mod
只是depth
从当前帧向上帧。否则,函数将从帧开始depth
从当前开始,继续向上调用堆栈,直到第一个模块 不同的 从提供的列表中。在这种情况下,finddiff
可以是模块或模块名称的列表。或者,它可以是True,它将使用模块depth
调用堆栈作为返回的模块与之最不相同。
- depth :
- 返回:
- 加薪:
ValueError
如果
finddiff
是包含无效项的列表。
实例
下面的示例假设在名为
pkg
.mod1.py
::def find1(): from astropy.utils import find_current_module print find_current_module(1).__name__ def find2(): from astropy.utils import find_current_module cmod = find_current_module(2) if cmod is None: print 'None' else: print cmod.__name__ def find_diff(): from astropy.utils import find_current_module print find_current_module(0,True).__name__
mod2.py
::def find(): from .mod1 import find2 find2()
这些模块就位后,会发生以下情况:
>>> from pkg import mod1, mod2 >>> from astropy.utils import find_current_module >>> mod1.find1() pkg.mod1 >>> mod1.find2() None >>> mod2.find() pkg.mod2 >>> find_current_module(0) <module 'astropy.utils.misc' from 'astropy/utils/misc.py'> >>> mod1.find_diff() pkg.mod1