如果一个文件myfile.py
包含:
class A(object):
# Some implementation
class B (object):
# Some implementation
我如何定义一个方法,以便在给定的情况下myfile.py
,它返回
[甲,乙]?
这里,A和B的返回值可以是类的名称或类的类型。
(i.e. type(A) = type(str) or type(A) = type(type))
您可以同时获得:
import importlib, inspect
for name, cls in inspect.getmembers(importlib.import_module("myfile"), inspect.isclass):
您可能还想检查:
if cls.__module__ == 'myfile'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)