Ask Your Question

Is there a way to prefix all sage code in order to include a custom module?

asked 2011-10-22 15:28:15 +0100

process91 gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-10-22 15:41:24 +0100

parzan gravatar image

If you create "~/.sage/init.sage" (where ~ is your homedir) it is executed automatically in the beginning of every session.

edit flag offensive delete link more


Which 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?

kcrisman gravatar imagekcrisman ( 2011-10-22 22:45:27 +0100 )edit

I think this works from the command line interface too, doesn't it?

Mike Witt gravatar imageMike Witt ( 2011-10-23 01:59:51 +0100 )edit

For me it works both in command line and notebook, but I am running the program on my computer as commented above.

parzan gravatar imageparzan ( 2011-10-23 03:03:45 +0100 )edit

@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 :)

kcrisman gravatar imagekcrisman ( 2011-10-24 11:51:14 +0100 )edit

This will work for me. I am using it as a server, but on my own hardware.

process91 gravatar imageprocess91 ( 2011-10-24 19:27:15 +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


Asked: 2011-10-22 15:28:15 +0100

Seen: 309 times

Last updated: Oct 22 '11