3

I don't want to write the same function in each Jupyter Notebook files. It would be easier if I just need to edit the function once without the need to edit in each .ipynb file.

The problem is, I have to restart kernel if I edit the .py file which will re-start everything.

Is there any way I can simply call a function from several .pynb files?

PS: After I have edited the .py, it does not affect the .ipynb file.

Jaya A
  • 145
  • 1
  • 8
  • You can run each `.pynb` fille by invoking `%run Untitled1.ipynb ` in the notebook and the function will be available in that notebook. – MEdwin Mar 11 '20 at 10:35

1 Answers1

5

Yes, you need a make .py file with function defined and import that file then call the functions in it. put it in the same folder as notebooks.

the filename.py file example

def function_name(param1,param2):
    #dosomting
    return

and how to import it

from filename import function_name

function_name(param1,param2)
mohsinali
  • 286
  • 1
  • 9