Ask Your Question
1

Making a collection of functions

asked 2018-01-27 20:25:00 +0100

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
1

answered 2018-01-27 20:35:37 +0100

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 myfile.py and there is a myfunction in it, you can import it as follows:

from myfile import myfunction
edit flag offensive delete link more

Comments

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

r2d2 gravatar imager2d2 ( 2018-01-27 20:50:02 +0100 )edit

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

r2d2 gravatar imager2d2 ( 2018-01-27 20:56:36 +0100 )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

Stats

Asked: 2018-01-27 20:25:00 +0100

Seen: 357 times

Last updated: Jan 27 '18