I use the following structure in the project:

CleanMaster - Libs - programclass - __init__.py - ShowScreens.py - main.py - program.py 

main.py - runs when the application starts and simply imports the main class of the Program from the module program.py

In the Libs / programclass package, I hold classes that I inherit in the Program class.

Example of the class architecture of the Program.py module:

 from Libs import programclass as program_class # классы программы class Program(program_class.ShowScreens): def __init__(self, **kvargs): super(Program, self).__init__(**kvargs) # Теперь мне доступны все атрибуты и методы класса ShowScreens. self.attribute_class_program = True 

The code of the __init__.py file from the Libs / programmclass package:

 from .ShowScreens import ShowScreens 

An example of the ShowScreens class architecture of the ShowScreens.py module from the Libs / programmclass package:

 class ShowScreens(object): # Здесь мне доступны все атрибуты и методы класса Program, # которые упомянуты в его конструкторе через ключевое слово self. print self.attribute_class_program 

Question: how correct is this approach?

  • It is not very clear what is meant by correctness. It seems to me that if it works in your project, and it suits you, it means - correctly. Not very clear, and here the inheritance of classes. Or are you talking about organizing modules and classes? I personally use a similar technique to conveniently break packages into modules. I'm a little embarrassed that you do not stick with PEP8. - Ilia w495 Nikitin
  • What does it mean, "I am not attached"? Sticking to! - Xyanight
  • python.org/dev/peps/pep-0008/#package-and-module-names quote: “Modules should have short, all-lowercase names . [...] Python packages should also have short, all-lowercase names , [...] ". - Ilia w495 Nikitin
  • Yes? Let it be honored by Guido van Rossum with his IDLE! : D - Xyanight
  • I guess this is like a historical legacy. It seems that IDEL appeared before the introduction of this rule. Similar problem with logging . + I am not saying that you are doing something bad, it just confuses me a little. - Ilia w495 Nikitin

0