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.Sat, 28 Nov 2015 15:38:24 -0600Saving my sage session into a .txt file from Interactive Shellhttp://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/ Hello guys, I have the following question:
Lets say i run a sage session and at the end i got this written in my Interactive Shell after the session
sage: Zmod(7)
Ring of integers modulo 7
sage: R.<x> = Zmod(7)[]
sage: R
Univariate Polynomial Ring in x over Ring of integers modulo 7
sage: RR = R.quotient(x^7 - 1)
sage: RR
Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 7 with modulus x^7 + 6
sage: f = RR(x^6-x^4+x^3+x^2-1)
sage: f
xbar^6 + 6*xbar^4 + xbar^3 + xbar^2 + 6
And now i want to save all of the above into a txt-file.
Is that possible and when yes how?Fri, 27 Nov 2015 15:02:48 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/Answer by nbruin for <p>Hello guys, I have the following question:</p>
<p>Lets say i run a sage session and at the end i got this written in my Interactive Shell after the session</p>
<pre><code>sage: Zmod(7)
Ring of integers modulo 7
sage: R.<x> = Zmod(7)[]
sage: R
Univariate Polynomial Ring in x over Ring of integers modulo 7
sage: RR = R.quotient(x^7 - 1)
sage: RR
Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 7 with modulus x^7 + 6
sage: f = RR(x^6-x^4+x^3+x^2-1)
sage: f
xbar^6 + 6*xbar^4 + xbar^3 + xbar^2 + 6
</code></pre>
<p>And now i want to save all of the above into a txt-file.
Is that possible and when yes how?</p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?answer=31113#post-id-31113IPython's `%history` magic command is probably what you're looking for. It has a `-f` option to redirect to a file. See `%history?` for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.
An alternative is to run inside an emacs buffer or "screen" and use its save functions. Fri, 27 Nov 2015 18:22:11 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?answer=31113#post-id-31113Comment by bruno171092 for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31171#post-id-31171IOError: [Errno 2] No such file or directory: '/home/nbruin/hist.txt'
I thank you a lot buddy. But i dont want to cause you any more trouble... Forget itSat, 28 Nov 2015 15:38:24 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31171#post-id-31171Comment by nbruin for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31170#post-id-31170Hm, how about (in the sage notebook)
H=open("/home/nbruin/hist.txt").read()
F=open(DATA+"hist.txt","w")
F.write(H)
F.close()
If you now instruct the browser that's displaying your notebook to reload the page, you should see the like appear in the "data" dropdown menu (if you select it). You can then open that file and work with that.Sat, 28 Nov 2015 15:18:24 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31170#post-id-31170Comment by bruno171092 for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31168#post-id-31168well the information is right except that my files arent saved there anyway.
and your tipp with notebook isnt working either.
"cp" is not defined...
I have no clue what sftop-ing is... and I somehow feel like i am a little bit too much of an computer noob to get it right...Sat, 28 Nov 2015 15:06:39 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31168#post-id-31168Comment by nbruin for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31167#post-id-31167Does the information at http://wiki.sagemath.org/SageAppliance#Sharing_files_between_Sage_and_Windows still apply? As long as you have one place that is accessible from both windows and your VM, you can move the file to that location for transport.
Come to think of it, you could try in the notebook:
sage: cp /home/sage/history.txt .
that should copy the file into the working directory of the active cell, and files dropped there should be hyperlinked. So if you access the notebook from a windows-based browser, you can possibly get at that file that way. Otherwise sftp-ing into the VM might be an option (PuTTY on windows has that capability I believe). This is just basic plumbing that you might want to learn anyway.Sat, 28 Nov 2015 14:03:11 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31167#post-id-31167Comment by bruno171092 for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31166#post-id-31166Well thanks a lot... I got out, that the path is
/home/sage
but unfortunately i have no clue how i get there... Sorry buddy, that i am still not able to do it after all your efforts :/Sat, 28 Nov 2015 13:52:52 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31166#post-id-31166Comment by nbruin for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31165#post-id-31165IPython would have saved it in the working directory of the process. If you do
sage: %history -f hist.txt
sage: ls hist.txt
hist.txt
You can confirm the file exists. To find out what the working directory is:
sage: pwd
u'/home/<something>'
Once you know where the file is, al you need to do is figure out a way of transferring files between your VM and the host OS. I hope that problem is addressed in the VM documentation somewhere.Sat, 28 Nov 2015 12:59:16 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31165#post-id-31165Comment by bruno171092 for <p>IPython's <code>%history</code> magic command is probably what you're looking for. It has a <code>-f</code> option to redirect to a file. See <code>%history?</code> for the relevant documentation. It may not be formatted exactly how you want, but it should get you pretty close.</p>
<p>An alternative is to run inside an emacs buffer or "screen" and use its save functions. </p>
http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31152#post-id-31152Hmm i used the history command.... but now i dont find the file -_-
I even searched for it with the windows-function... but nothign is found...
God... that Virtual Machine for Windows is frustrating... Do you have Linux or Windows yourself?Sat, 28 Nov 2015 04:15:42 -0600http://ask.sagemath.org/question/31110/saving-my-sage-session-into-a-txt-file-from-interactive-shell/?comment=31152#post-id-31152