假设以下代码:
class Person():
def __init__(self,name):
self.name = name
class Student(Person): pass
class Teacher(Person): pass
John = Student('John')
Tom = Student('Tom')
Victor = Teacher('Victor')
运行脚本后,类Person
通过
In [22]: Person.__subclasses__()
Out[22]: [__main__.Student, __main__.Teacher]
如何找到类Student
的所有实例,如:
Student.__instances__()
AttributeError: type object 'Student' has no attribute '__instances__'