Ask Your Question
1

Automatically attach file on starting shell?

asked 5 years ago

hwong557 gravatar image

updated 5 years ago

Is there a way to run sage from command line and have sage automatically run a command (such as attaching a file)? I do not want to put the attach command in the init.sage file, because I want sage to only attach my code when I am working on my project, not for general use.

Perhaps another way of thinking about is how can I run a sage script, and have it exit into an interactive shell? Then I would be able to run sage mycode.sage, and have the desired behavior.

Thank you.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

Sébastien gravatar image

updated 5 years ago

In the file ~.sage/init.sage, you may write the following code:

import os
if os.path.exists('init.sage'):
    %runfile init.sage

which will automatically run the file init.sage if there is such a file in the current folder. Then, you can put your desired code in that file in your working directory which will get run first when you start sage.

Preview: (hide)
link

Comments

2

I think you may want to use a different name in the %runfile command; otherwise starting up sage with ~/.sage as current directory could lead to an unpleasant experience.

nbruin gravatar imagenbruin ( 5 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: 5 years ago

Seen: 701 times

Last updated: Jan 19 '20