Ask Your Question

Automatically attach file on starting shell?

asked 2020-01-19 17:20:47 +0200

hwong557 gravatar image

updated 2020-01-19 17:21:39 +0200

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

answered 2020-01-19 18:59:36 +0200

Sébastien gravatar image

updated 2020-01-19 19:00:10 +0200

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



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 20:09:24 +0200 )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: 2020-01-19 17:20:47 +0200

Seen: 380 times

Last updated: Jan 19 '20