I am new to Jupyter Notebooks and using the Anaconda install for Python 3.7. What is the best way to execute a function from another notebook? I found this 2-year-old answer here, but I don't know if there is a new/better way to do it with the Anaconda install (nbimporter has to be installed separately, it's not in Anaconda).
Here is the code/info in the notebooks:
Try #1 (fail)
# working directory files:
# mytest.ipynb # this contains the function I am trying to call
# Untitled.ipynb # this is the Notebook I am working in
# mytest.ipynb contents:
def testfcn(x):
return print("input is", str(x))
# Untitled.ipynb contents:
from mytest import testfcn
testfcn(4)
ModuleNotFoundError: No module named 'mytest'
Try #2 (okay, not ideal)
# Untitled.ipynb contents:
%run mytest.ipynb
testfcn(4)
# returns this, extra stuff:
0.019999999999999997
<class 'float'>
input is 4