What are the expanding Python application architectures?
If I take the PLO, now I'm trying to get access to preschool classes on the same page as what happens to properties. I think it's the most readable, because, looking at the challenge, it becomes clear at the moment that the object inherits. And the last element will always be method or characteristic.
I'll explain. So, catalogue:
cgi-bin ├── a.py └── a ├── __init__.py ├── b.py └── b ├── __init__.py ├── c.py └── c └── ...
Component content a.py:
class a: prop = 5
Component content b.py:
class b (a): test = 7
Files __init__.py packages are empty. After importing, I tried to access as follows:
a.prop a.b.prop a.b.test
But, of course, it doesn't work:
import a import a.b
The import priority of the package is higher than the import priority of the module (packet) a and module a in one directory. If my approach has the right to life, please indicate how to bring it to work, given the priority of imports. If there is a more understandable and expanding architecture, please demonstrate. I'm just starting to understand my language. Thank you!
I think you're overcomplicating the structure.
In your attempt to solve this, there's a problem with the fact that it's rather informal to import a module that matches the package name.
The second problem is that the class and module will be different objects, and this treatment of the successor classes, as you plan, will not work.
For starters, it's worth considering whether the classes really need, or whether there are enough modules and functions. The functionality of the modules should then be properly delineated, where necessary creating the packages.
To ensure that access to the packages entered does not require a complete route to the facility, files
__init__.pyThe necessary facilities can be imported to a level higher and further. How to use this file can be read on the question. https://ru.stackoverflow.com/questions/420987/%D0%9E%D0%B1%D1%80%D0%B0%D1%89%D0%B5%D0%BD%D0%B8%D0%B5-%D0%BA-%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%B8-%D0%B7%D0%B0%D0%B4%D0%B0%D0%BD%D0%BD%D0%BE%D0%B9-%D0%B2-init-py/420994#420994 ♪
However, with great desire, such behaviour can still be implemented using meta-classes (the decision is given only for example, should not be used in the real programme):
class MagicianAncestor(type): def __init__(cls, what, bases=None, dict_=None): super().__init__(what, bases, dict_)
for ancestor in bases: if type(ancestor) is not MagicianAncestor: continue setattr(ancestor, cls.__name__, cls)
prop_a = 5
prop_b = 10
prop_c = 15
prop_d = 20
a = A()
print(a.B.prop_b) # 10
print(a.B.prop_a) # 5
print(a.C.prop_c) # 15
print(a.C.prop_a) # 5
print(a.B.D.prop_d) # 20
print(a.D.prop_d) # AttributeError