Ask Your Question
1

Making a collection of functions

asked 7 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 7 years ago

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
Preview: (hide)
link

Comments

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

r2d2 gravatar imager2d2 ( 7 years ago )

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

r2d2 gravatar imager2d2 ( 7 years ago )

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: 7 years ago

Seen: 406 times

Last updated: Jan 27 '18