Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法获取仅由用户定义的类列表?
到目前为止,我可以使用以下内容显示模块中所有类的列表:
inspect.getmembers(sys.modules[__name__])
问题是我得到了一个列表特殊方法和其他东西。谢谢你。
最后我这样做了:
from folder1 import module_name as mod for name, cls in mod.__dict__.items(): if isinstance(cls, type): klass = getattr(mod, name)