Python:inspect获取模块下的所有类对象

# -*- coding:utf-8 -*-


class A:
    pass


class B:
    pass


if __name__ == '__main__':

    import inspect
    import sys

    for name, class_ in inspect.getmembers(sys.modules[__name__], inspect.isclass):
        print(name, class_)
    """
    A <class '__main__.A'>
    B <class '__main__.B'>
    """
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页