【发布时间】:2022-07-27 23:33:04
【问题描述】:
我有一个应该在文件中实现的类列表。我需要获取文件中的所有类并检查类名是否已经在列表中。
例子:
ls = ['Hello','Foo','Bar']
list_of_classes = [] # I need to get list of all classes in a file
# then I could simply find out which classes are not implemented
【问题讨论】:
-
要获取文件中类的名称,您可以导入它,然后将其名称传递给 dir 函数:
import file然后print(dir(file)) -
太好了,谢谢!
标签: python python-3.x class instance