I feel like I'm missing something simple and basic. Here's a toy setup
PythonProject/
main.py
x/
a.py
y/
b.py
b.py has a function foo with no dependencies
def foo():
print("Hello World")
a.py needs foo from b.py to work and imports it directly
import y.b
def bar():
#Do some stuff
y.b.foo()
main.py needs bar from a.py
import x.a
x.a.bar()
Now, running a.py works just fine, it successfully imports b and finds foo. Trying to run main.py however breaks with an import error: specifically "import b" fails during "import a"
I get the impression that what needs to happen is that b
needs to be exposed by an __init__.py
in a/
but I'm unsure what the pythonic way of doing this would be.
What is the preferred solution to importing a module (a) which imports another module (b) preferably without bringing PythonProject awareness to a?