0

I have a complicated folder structure that contains many files in folders and sub-folders. I would like to generate a list of all classes that inherit for the "experiment" class so that I can import them. again only if they inherit from the class experiment.

I tried this:

import inspect
for name, obj in inspect.getmembers(sys.modules[__name__]):
    if inspect.isclass(obj):
        print(obj)

It prints all classes and I suppose I could check them later on but it doesnt iterate over all folders and subfolders, just looks in the top level. I could use os.walk but is there an easier way?

Bob Gilmore
  • 11,154
  • 13
  • 49
  • 52
  • 2
    What have you tried? What isn't working? Stack Overflow is not a code-writing service, and even if it was, you haven't given nearly enough information for anyone to make a reasonable attempt. – ShadowRanger Dec 29 '16 at 01:24
  • 1
    To find all the classes, you will have import *everything* in your folder structure. There is no built-in shortcut for that. – ekhumoro Dec 29 '16 at 01:55
  • @AkshatMahajan. That is only relevant for classes in modules that have already been imported. – ekhumoro Dec 29 '16 at 01:58
  • @ekhumoro Yes. But since importing everything in your folder structure is required anyway... – Akshat Mahajan Dec 29 '16 at 03:18

0 Answers0