Ask Your Question
0

Saving my sage session into a .txt file from Interactive Shell

asked 2015-11-27 22:02:48 +0100

bruno171092 gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-11-28 01:22:11 +0100

nbruin gravatar image

IPython'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.

edit flag offensive delete link more

Comments

Hmm 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?

bruno171092 gravatar imagebruno171092 ( 2015-11-28 11:15:42 +0100 )edit

IPython 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.

nbruin gravatar imagenbruin ( 2015-11-28 19:59:16 +0100 )edit

Well 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 :/

bruno171092 gravatar imagebruno171092 ( 2015-11-28 20:52:52 +0100 )edit

Does the information at http://wiki.sagemath.org/SageApplianc... 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.

nbruin gravatar imagenbruin ( 2015-11-28 21:03:11 +0100 )edit

well 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...

bruno171092 gravatar imagebruno171092 ( 2015-11-28 22:06:39 +0100 )edit

Hm, 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.

nbruin gravatar imagenbruin ( 2015-11-28 22:18:24 +0100 )edit

IOError: [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 it

bruno171092 gravatar imagebruno171092 ( 2015-11-28 22:38:24 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-11-27 22:02:48 +0100

Seen: 1,492 times

Last updated: Nov 28 '15