ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 27 Jan 2018 13:56:36 -0600Making a collection of functionshttp://ask.sagemath.org/question/40811/making-a-collection-of-functions/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?Sat, 27 Jan 2018 13:25:00 -0600http://ask.sagemath.org/question/40811/making-a-collection-of-functions/Answer by tmonteil for <p>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?</p>
http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?answer=40812#post-id-40812It 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
Sat, 27 Jan 2018 13:35:37 -0600http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?answer=40812#post-id-40812Comment by r2d2 for <p>It you put a <code>.py</code> 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 <code>myfile.py</code> and there is a <code>myfunction</code> in it, you can import it as follows:</p>
<pre><code>from myfile import myfunction
</code></pre>
http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?comment=40814#post-id-40814No problem! I figured it out. Just "import myfile" works just fine.Sat, 27 Jan 2018 13:56:36 -0600http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?comment=40814#post-id-40814Comment by r2d2 for <p>It you put a <code>.py</code> 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 <code>myfile.py</code> and there is a <code>myfunction</code> in it, you can import it as follows:</p>
<pre><code>from myfile import myfunction
</code></pre>
http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?comment=40813#post-id-40813Thank you for your answer! what if I want to import all the functions at once though?Sat, 27 Jan 2018 13:50:02 -0600http://ask.sagemath.org/question/40811/making-a-collection-of-functions/?comment=40813#post-id-40813