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, 24 Oct 2011 12:27:15 -0500Is there a way to prefix all sage code in order to include a custom module?http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/I have a library of commonly used functions and variables which I import, when required, into sage by using the following commands:
import os, sys
cmd_folder = '/home/username/sage'
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
import defaults as d
This allows me to access all my frequently used saved functions and variables. I essentially only use Sage through the web interface, and I would like to know if it is possible to make this code run as a "prefix" so that I no longer have to type this include in every worksheet.Sat, 22 Oct 2011 08:28:15 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/Answer by parzan for <p>I have a library of commonly used functions and variables which I import, when required, into sage by using the following commands:</p>
<pre><code>import os, sys
cmd_folder = '/home/username/sage'
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
import defaults as d
</code></pre>
<p>This allows me to access all my frequently used saved functions and variables. I essentially only use Sage through the web interface, and I would like to know if it is possible to make this code run as a "prefix" so that I no longer have to type this include in every worksheet.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?answer=12798#post-id-12798If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.Sat, 22 Oct 2011 08:41:24 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?answer=12798#post-id-12798Comment by parzan for <p>If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21060#post-id-21060For me it works both in command line and notebook, but I am running the program on my computer as commented above.Sat, 22 Oct 2011 20:03:45 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21060#post-id-21060Comment by kcrisman for <p>If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21062#post-id-21062Which of course will only work if you are using it in the web interface off your own computer! But it looks like that's the case here?Sat, 22 Oct 2011 15:45:27 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21062#post-id-21062Comment by process91 for <p>If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21043#post-id-21043This will work for me. I am using it as a server, but on my own hardware.Mon, 24 Oct 2011 12:27:15 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21043#post-id-21043Comment by Mike Witt for <p>If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21061#post-id-21061I think this works from the command line interface too, doesn't it?Sat, 22 Oct 2011 18:59:51 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21061#post-id-21061Comment by kcrisman for <p>If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.</p>
http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21051#post-id-21051@Mike Witt: Yes, init.sage should work in both, but it wasn't clear whether process91 is using it on a remote server or on his/her own computer. "Only" modified "your own computer", not the whole following phrase :)Mon, 24 Oct 2011 04:51:14 -0500http://ask.sagemath.org/question/8407/is-there-a-way-to-prefix-all-sage-code-in-order-to-include-a-custom-module/?comment=21051#post-id-21051