def get_containing_module(value):
"""
Return the name of the module containing the given value, or
C{None} if the module name can't be determined.
@rtype: L{DottedName}
"""
if inspect.ismodule(value):
return DottedName(value.__name__)
elif isclass(value):
return DottedName(value.__module__)
elif (inspect.ismethod(value) and value.im_self is not None and
value.im_class is ClassType): # class method.
return DottedName(value.im_self.__module__)
elif inspect.ismethod(value):
return DottedName(value.im_class.__module__)
elif inspect.isroutine(value):
module = _find_function_module(value)
if module is None: return None
return DottedName(module)
else:
return None
评论列表
文章目录