ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 May 2018 05:09:48 -0500save and rerun lists of sage commandshttp://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/ 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 ?Thu, 17 May 2018 09:42:59 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/Comment by FrédéricC for <p>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 ?</p>
http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42368#post-id-42368make a text file with the extension .sage
http://doc.sagemath.org/html/en/tutorial/programming.html#loading-and-attaching-sage-filesFri, 18 May 2018 14:16:52 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42368#post-id-42368Answer by eric_g for <p>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 ?</p>
http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42363#post-id-42363You 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.Thu, 17 May 2018 14:10:16 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42363#post-id-42363Answer by francesco62 for <p>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 ?</p>
http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42367#post-id-42367I 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.Fri, 18 May 2018 10:58:10 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42367#post-id-42367Comment by eric_g for <p>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.</p>
http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42381#post-id-42381OK, I've edited my answer accordingly.Mon, 21 May 2018 05:09:48 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42381#post-id-42381Answer by John Palmieri for <p>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 ?</p>
http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42373#post-id-42373Here 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/tutorial/interactive_shell.html#saving-and-loading-complete-sessions. (I've never actually done this, but I use `%attach` all the time.)Sat, 19 May 2018 10:25:12 -0500http://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42373#post-id-42373