A clean way to organize and load files with subclasses

后端 未结 2 1433
無奈伤痛
無奈伤痛 2020-12-12 05:21

I have a parent class that provides abstract functions for manipulating hardware, and a directory full of classes that subclass this parent class, and provide hardware-speci

2条回答
  •  时光说笑
    2020-12-12 05:52

    The basic idea of dividing the sub classes int different files and importing only what you need is very pythonic. Consider using a __init__.py file in your subclasses' folder with an import SubClass1, SubClass2, SubClass3, ...-command in it. Then you can just say in the main.py:

    import folderOfSubClasses
    

    Then the __init__.py file will be executed and you have the expected result.

    I hope I could help you!

提交回复
热议问题