First time here? Check out the FAQ!

Ask Your Question
1

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

asked 13 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

parzan gravatar image

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

Preview: (hide)
link

Comments

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 ( 13 years ago )

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

Mike Witt gravatar imageMike Witt ( 13 years ago )

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 ( 13 years ago )

@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 ( 13 years ago )

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

process91 gravatar imageprocess91 ( 13 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: 13 years ago

Seen: 421 times

Last updated: Oct 22 '11