【问题标题】:Compare 2 python files and find missing classes比较 2 个 python 文件并找到缺失的类
【发布时间】: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


【解决方案1】:

我可以通过使用 dir() 函数来解决问题,正如 Nicolo Teseo 在 cmets 部分中提到的那样。 谢谢!

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多