ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 21 May 2018 12:09:48 +0200save and rerun lists of sage commandshttps://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 16:42:59 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/Answer 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>
https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=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 21:16:52 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42368#post-id-42368Answer 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>
https://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 17:25:12 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42373#post-id-42373Answer 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>
https://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 21:10:16 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?answer=42363#post-id-42363Comment by eric_g for <p>You can use</p>
<pre><code>%history -f my_session.sage
</code></pre>
<p>This saves all the sage commands typed during your session in the text file <code>my_session.sage</code>. Then, you can load this file in a new Sage session by</p>
<pre><code>%load my_session.sage
</code></pre>
<p>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 <code>...:</code> to rerun the commands and possibly enter <code>n</code> to the question</p>
<pre><code>File u'my_session.sage' exists. Overwrite?
</code></pre>
<p>This occurs because the <code>%history</code> command has been saved in the file <code>my_session.sage</code> and therefore is run again when you load the file.</p>
<p>An alternative is to use <code>%attach</code> as described in @John_Palmieri's answer.</p>
https://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 12:09:48 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42381#post-id-42381Comment by francesco62 for <p>You can use</p>
<pre><code>%history -f my_session.sage
</code></pre>
<p>This saves all the sage commands typed during your session in the text file <code>my_session.sage</code>. Then, you can load this file in a new Sage session by</p>
<pre><code>%load my_session.sage
</code></pre>
<p>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 <code>...:</code> to rerun the commands and possibly enter <code>n</code> to the question</p>
<pre><code>File u'my_session.sage' exists. Overwrite?
</code></pre>
<p>This occurs because the <code>%history</code> command has been saved in the file <code>my_session.sage</code> and therefore is run again when you load the file.</p>
<p>An alternative is to use <code>%attach</code> as described in @John_Palmieri's answer.</p>
https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=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 17:58:10 +0200https://ask.sagemath.org/question/42362/save-and-rerun-lists-of-sage-commands/?comment=42367#post-id-42367