import a as module_to_check
print(
'checking module "{}"'
.format(module_to_check.__name__))
for attr in dir(module_to_check):
if callable(getattr(module_to_check, attr)):
print(
'function "{}" came from module "{}"'
.format(
getattr(module_to_check, attr).__name__,
getattr(module_to_check, attr).__module__))
输出为:
checking module "a"
function "a_2" came from module "a"
function "b_2" came from module "b"
解决方案的关键是
function_name.__module__
。考虑以下代码:输出为:
a.py
是:b.py
是:相关问题 更多 >
编程相关推荐