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.Mon, 11 Dec 2017 16:28:16 -0600Importing user SAGE files "pythonically"http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/Hello,
I'm wondering if there's a more "pythonic" way in which to import user-written SAGE modules.
For instance, I'm able to load in a SAGE file I've written using the `load` keyword.
load(path_to_sage_file)
That's all well and good, however, as I start to import more and more user SAGE files, where certain functions are coming from becomes less clear. It would be ideal to do something like
from name_of_sage_file import name_of_sage_function
However, this doesn't seem to work. Is there a more "pythonic" way in which to go about doing this? Thanks!Sat, 09 Dec 2017 09:15:19 -0600http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/Answer by slelievre for <p>Hello, </p>
<p>I'm wondering if there's a more "pythonic" way in which to import user-written SAGE modules. </p>
<p>For instance, I'm able to load in a SAGE file I've written using the <code>load</code> keyword. </p>
<pre><code>load(path_to_sage_file)
</code></pre>
<p>That's all well and good, however, as I start to import more and more user SAGE files, where certain functions are coming from becomes less clear. It would be ideal to do something like</p>
<pre><code>from name_of_sage_file import name_of_sage_function
</code></pre>
<p>However, this doesn't seem to work. Is there a more "pythonic" way in which to go about doing this? Thanks!</p>
http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?answer=40041#post-id-40041See the related Ask Sage question:
[https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/](https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/).
See also this template for packaging Sage code as a Python module:
[https://github.com/sagemath/sage_sample/](https://github.com/sagemath/sage_sample/).
See also these slides by Marc Masdeu about packaging Sage code as a Python module and distributing it:
[https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way](https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way).
Sat, 09 Dec 2017 12:04:55 -0600http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?answer=40041#post-id-40041Comment by slelievre for <p>See the related Ask Sage question:
<a href="https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/">https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/</a>.</p>
<p>See also this template for packaging Sage code as a Python module:
<a href="https://github.com/sagemath/sage_sample/">https://github.com/sagemath/sage_sample/</a>.</p>
<p>See also these slides by Marc Masdeu about packaging Sage code as a Python module and distributing it:
<a href="https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way">https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way</a>.</p>
http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?comment=40114#post-id-40114Do you see a place in the documentation where this would fit well? Please suggest a change.
One way the documentation gets better is when this "why-oh-why" feeling makes users take action!Mon, 11 Dec 2017 16:28:16 -0600http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?comment=40114#post-id-40114Comment by Vincent Russo for <p>See the related Ask Sage question:
<a href="https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/">https://ask.sagemath.org/question/33954/can-i-create-a-sage-file-and-import-it-as-a-python-module/</a>.</p>
<p>See also this template for packaging Sage code as a Python module:
<a href="https://github.com/sagemath/sage_sample/">https://github.com/sagemath/sage_sample/</a>.</p>
<p>See also these slides by Marc Masdeu about packaging Sage code as a Python module and distributing it:
<a href="https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way">https://www.slideshare.net/mmasdeu/distributing-sage-python-code-the-right-way</a>.</p>
http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?comment=40049#post-id-40049Why-oh-why is this not more explicitly stated in the documentation. Thank you, good sir.Sat, 09 Dec 2017 18:09:37 -0600http://ask.sagemath.org/question/40036/importing-user-sage-files-pythonically/?comment=40049#post-id-40049