My package has the following structure:
myPackage
-- __init__.py <-- empty
-- signal.py
-- plot.py
signal.py contains:
from plot import plot_signal
def build_filter():
...
def other_function():
plot_signal()
plot.py contains:
from signal import build_filter
def plot_signal():
...
def other_function():
build_filter()
I then have my script that makes use of this package that contains something like:
import myPackage as mp
mp.plot.plot_signal()
When I run this I get an attribute error: module 'myPackage' has no attribute 'plot'
I'm not sure why its referring to plot
as an attribute when its a module in my package, or why its referring to myPackage
as a module.
I then tried importing my package and calling the function a different way:
from myPackage import plot, signal
plot.plot_signal()
However, now I get an import error: cannot import name 'build_filter'
and the traceback is referring to plot.py
where its trying to import the build_filter()
function from a sibling module.
I'm thinking this has something to do with the fact that the 2 modules are using functions from one another, and recursively importing the other module.
What's the correct way to organize this package so that sibling modules can import functions from each other?