Is there a way to track descendants of the base class?

I don't quite know how to explain but you can somehow track down the descendants of the base class or something else? Distribute example. Here the class is added into the list if its flag decorator. But the problem is that if you make this marked class to a different file, then nothing will happen, because Python will interpret the file. What is a way to add marked classes if they are in other files.

link to example
tyk
April 19th 20 at 12:22
2 answers
April 19th 20 at 12:24
Solution
If the file is not interpretable, then the class does not exist. Of course, you can use magic and glob importlib/os.walk, but what for it to you?
Write noodles - Major5 commented on April 19th 20 at 12:27
I think to store these files in a separate folder and just start them. Maybe there is a better option? - Major5 commented on April 19th 20 at 12:30
April 19th 20 at 12:26
I'm not sure I understand the question, but probably __subclasses__* is what you are looking for:

>>> class BaseClass:
... pass
...
>>> class Cl1(BaseClass):
... pass
...
>>> class Cl2(BaseClass):
... pass
...
>>> BaseClass.__subclasses__()
[<class '__main__.Cl1'>, <class '__main__.Cl2'>]


* — python3
The problem is that these class files not interpreted - Major5 commented on April 19th 20 at 12:29

Find more questions by tags Python