Hello folks! I'm quite a bit puzzled regarding Python packages, what __init__.py should look like etc.
Let's say I have this structure:
Code:
In each of the class files, there is a class defined, and they might all refer to each other. So class A might use class C and class C might use class A. Thus, we need to import them. However, doing so at top-level gives me a circular import exception, which does make sense. My thoughts are to do magic in the 3 __init__.py files, but I've honestly no idea how.
Can someone give me clues what the contents of each __init__.py file should look like, and how I should import class C from class A (for example)?
Also, one should be able to import every class/function in the package via from mypackage import * (i.e. make everything available to the global scope without having to use the mypackage. prefix. How would I go with that? Thanks in advance
Let's say I have this structure:
Code:
mypackage/
__init__.py
folder1/
__init__.py
classA.py
classB.py
folder2/
__init__.py
classC.py
In each of the class files, there is a class defined, and they might all refer to each other. So class A might use class C and class C might use class A. Thus, we need to import them. However, doing so at top-level gives me a circular import exception, which does make sense. My thoughts are to do magic in the 3 __init__.py files, but I've honestly no idea how.
Can someone give me clues what the contents of each __init__.py file should look like, and how I should import class C from class A (for example)?
Also, one should be able to import every class/function in the package via from mypackage import * (i.e. make everything available to the global scope without having to use the mypackage. prefix. How would I go with that? Thanks in advance