Ask Your Question

Making a collection of functions

asked 2018-01-27 13:25:00 -0600

r2d2 gravatar image

I have a somewhat large collection of functions that I wrote myself to make some computations. They are all very much dependent on each other so if I ever want to use some subset of them, say when I'm working in some Jupyter notebook, I have to copy paste the whole bunch of them into a cell and evaluate it. This makes the notebook really bulky and ugly. Is there anyway I can make these functions into a package so that I can just import it in any jupyter notebook that's in the same folder to use those functions?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-01-27 13:35:37 -0600

tmonteil gravatar image

It you put a .py file in the same directory as where the file is (and where you launch the jupyter from), you can import it as a Python module, e.g. if your file is and there is a myfunction in it, you can import it as follows:

from myfile import myfunction
edit flag offensive delete link more


Thank you for your answer! what if I want to import all the functions at once though?

r2d2 gravatar imager2d2 ( 2018-01-27 13:50:02 -0600 )edit

No problem! I figured it out. Just "import myfile" works just fine.

r2d2 gravatar imager2d2 ( 2018-01-27 13:56:36 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-01-27 13:25:00 -0600

Seen: 33 times

Last updated: Jan 27