Hi I'm new to python and think I have a problem with the program structure I built.
This is an extract of the structure I thought of.
.
└── asd
├── asd.py
├── __init__.py
├── Framework
│ ├── importer.py
│ └── __init__.py
├── Library
│ ├── libraryManager.py
│ └── __init__.py
in reality there are many more packages under asd
. asd.py
is meant to be the 'main'. It instantiates many objects of the different classes contained in the other packages, for example it has several libraryManager objects. The importer can import (not only) library files.
I think my key flaw is the following: To enable the classes within the different packages to access each others instances of asd
they get a reference to the main asd
as a parameter.
Those are the files in question:
asd.py
:
from asd.Framework.importer import importer
from asd.Library.libraryManager import libraryManager
class asd(object):
def __init__(self):
# instantiate several objects
self.nodeLibMng = libraryManager("DbNodeLibrary.txt")
self.importer = importer(self)
importer.py
:
from asd.asd import asd
class importer(object):
def __init__(self, asdRef : asd):
self.asdRef = asdRef
def importNode (self,item):
# The following line shows why I want this reference construct.
self.asdRef.nodeLibMng.appendItemToLibraryDB(item)
Now if I want to run the asd.py I get the following Error:
ImportError: No module named 'asd.Framework'; 'asd' is not a package
If I run a test code within the importer.py I get this error:
ImportError: cannot import name 'asd'
other topics like ImportError: Cannot import name X suggest that I have circular dependent imports.
So how can I solve this, but keep the behaviour, that every class can communicate with the instances of asd
?
EDIT 0:
I'm starting the asd.py
or importer.py
by adding
if __name__ == '__main__':
asd=asd()