I have a problem when I try to have a cyclic import in Python 3. I am writing a PyQt4 app and I want to make some object available in the whole app. This way I end up having some files:
index.py
import source.blab as bl
source/blab.py
import source.windows
windows = source.windows.Windows()
source/windows.py
import source.window_clients.main_window
class Windows:
...
source/window_clients/main_window.py
import source.blab
class MainWindow(QWidget):
...
So far, the code works. However, for aesthetic reasons, I would like to change the import command in main_window.py
into:
import source.blab as bl
which throws an:
AttributeError: module 'source' has no attribute 'blab'
I am sure, this is related to Circular (or cyclic) imports in Python where they say that one cannot use from a * import b
in a cyclic import. Is it the same for import a as b
? If so, is there another way to change the name of the imported module?