Sharing functions/code files across Jupyter notebook

I wrote some functions (for e.g some non-standard metrics for binary/multiclass) which I want to be able to use whenever I’m doing binary classification. In Jupyter/google colab, I just copy-paste those functions in every notebook.

  • What’s the general practise for using common code while using jupyter notebooks? Google search shows some results to share code, but I couldn’t figure out if there is any standard approach while using Jupyter notebooks.

  • If the project spans more than one logical units/files, is jupyter notebook still a good choice?

Any inputs will be very helpful.

For jupyter notebooks running on local machines, you can create your own python package, and include functions that are frequently used. You can then import them as and when required in your notebooks.

2 Likes

Great!
How about arranging a multi-file project.
I understand its possible, but I want to know what is considered efficient, and good practise.

Yeah you can create a Python package (which is a directory) which can contain multiple Python files, each of which will be treated as a module.