I'm trying to import a function from a higher level directory. I believe converting my script to a python "package" is the best way to do this:
package/
__init__.py # contains add function
subpackage/
__init__.py
my_script.py # where I want to import add function
Let's say the function I want to import is simple:
def add(x, y):
return x + y
I should be able to do something like this in my_script.py
, per the python docs:
from package import add
print(add(5, 6))
But I'm getting a ModuleNotFoundError: No module named 'package'
error. What am I doing wrong?