Ask Your Question

save and rerun lists of sage commands

asked 2018-05-17 16:42:59 +0100

francesco62 gravatar image

How can I save the list of sage ( not phyton ) commands in a text file? I want to utilize it into sage shell, so that I don't rewrite them again? Is it possible ?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2018-05-17 21:10:16 +0100

eric_g gravatar image

updated 2018-05-21 12:11:05 +0100

You can use

%history -f my_session.sage

This saves all the sage commands typed during your session in the text file my_session.sage. Then, you can load this file in a new Sage session by

%load my_session.sage

In the Jupyter notebook, this loads all the saved commands in a single cell. In the Sage console, you will have to press Enter at the prompt ...: to rerun the commands and possibly enter n to the question

File u'my_session.sage' exists. Overwrite?

This occurs because the %history command has been saved in the file my_session.sage and therefore is run again when you load the file.

An alternative is to use %attach as described in @John_Palmieri's answer.

edit flag offensive delete link more


I know how to obtein sage commands, but I want to save this list in a text file. Next I want to use again this file to send these commands to sage shell without retype them again.

francesco62 gravatar imagefrancesco62 ( 2018-05-18 17:58:10 +0100 )edit

OK, I've edited my answer accordingly.

eric_g gravatar imageeric_g ( 2018-05-21 12:09:48 +0100 )edit

answered 2018-05-18 21:16:52 +0100

FrédéricC gravatar image

make a text file with the extension .sage

edit flag offensive delete link more

answered 2018-05-19 17:25:12 +0100

Here are several options:

  • as @FrédéricC says, create a file with a .sage extension containing your commands, say my_file.sage, and then while running Sage, use the command %attach /path/to/.../my_file.sage. Using %attach means that if you edit the file while Sage is running, it will automatically reload it, re-executing all of the commands.

  • if you don't mind a non-text file, you can save your Sage session: see (I've never actually done this, but I use %attach all the time.)

edit flag offensive delete link more

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: 2018-05-17 16:42:59 +0100

Seen: 772 times

Last updated: May 21 '18