Ask Your Question
1

Automatically attach file on starting shell?

asked 2020-01-19 10:20:47 -0600

hwong557 gravatar image

updated 2020-01-19 10:21:39 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2020-01-19 11:59:36 -0600

Sébastien gravatar image

updated 2020-01-19 12:00:10 -0600

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.

edit flag offensive delete link more

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 ( 2020-01-19 13:09:24 -0600 )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

Stats

Asked: 2020-01-19 10:20:47 -0600

Seen: 60 times

Last updated: Jan 19