Ask Your Question
2

save and rerun lists of sage commands

asked 7 years ago

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 ?

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
1

answered 7 years ago

FrédéricC gravatar image

make a text file with the extension .sage

http://doc.sagemath.org/html/en/tutor...

Preview: (hide)
link
1

answered 7 years ago

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 http://doc.sagemath.org/html/en/tutor.... (I've never actually done this, but I use %attach all the time.)

Preview: (hide)
link
1

answered 7 years ago

eric_g gravatar image

updated 7 years ago

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.

Preview: (hide)
link

Comments

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

OK, I've edited my answer accordingly.

eric_g gravatar imageeric_g ( 7 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: 7 years ago

Seen: 1,296 times

Last updated: May 21 '18