rahul_88 rahul_88 - 1 month ago 6
Python Question

How to run an existing function from Jupyter notebook

I am using Jupyter notebook. In the same folder in which the notebook is running, I have a function f defined as

def f(x):
return x**2

I have saved this function as f.py in the same folder. Now I want to call this function in the notebook that is running. How do I do that? If the function was typed into the notebook, I could have just typed


Answer Source

Try the load magic;

%load f.py

That automatically loads the in the entire contents of file so that you can edit it in a cell.

from f import f

Is another option.

If neither one of those work for you check out the solution to this question.