Suppose the following code:
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')
After the script is run, class Person
is aware of its subclasses through
In [22]: Person.__subclasses__()
Out[22]: [__main__.Student, __main__.Teacher]
How to find all instances of class Student
like:
Student.__instances__()
AttributeError: type object 'Student' has no attribute '__instances__'