Ask Your Question
0

saving calculated results problem

asked 2012-10-17 05:11:55 +0100

anonymous user

Anonymous

I have a few vectors as calculated results, how do I write them to a file/files so I can retrieve them in the notebook later?

I tried save and load, but whenever I restart the workbook, I cannot get my objects back.

The examples in Sage always use SAGE_TMP as the file name, if I change the name, I cannot even save the object.

If I do use SAGE_TMP, is it kind of like a clipboard, can only store one object at a time?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-10-17 06:39:37 +0100

Volker Braun gravatar image

SAGE_TMP is the Sage temp directory. This will always be deleted after you quit Sage, so as the name implies you should only use it for temporary files.

You need sufficient permissions to save a file anywhere else. If you run the sage server yourself then you should be able to save files anywhere in your home directory. On sagenb.org you obviously can't write files anywhere outside of SAGE_TMP

If the data you want to store is not too long then you can just pickle them into a string:

sage: v = vector([1,2/3,4/5])
sage: v
(1, 2/3, 4/5)
sage: v.dumps()
'x\x9cu\x8f\xbbN\x031\x10E\x958\x810\x10\x1e\x7f\x01\x8d\xa3\xe5\xf1\x0biVPX\xda2\xb2\x1c\xefd\xb1\xd6\xb13~D\xa2@\xa2A\xc0_\xb3\tK*\xe8\xce-\xce\x9d;oC\x1dU\x83|\xed\xebl1\xf2-\xea\xe4\x83\x0c*\x19\xef\x94\x955\xba\x88\x90\xdd\xc6\xe8\xd6\xa2\xdc\x16@\x83\xeb\x1f%\xa6\x90u\xca\x01\xf9J\xed\xa4\x17h\xd0a0Z\xf6Y\xfej@\xc3\x7f\x1d\xeb}\x9b7\xb2\xb1~\xa9,\x10\xab`\x1e\x10\x1f\xf7sh\xf4.h\\\x8e\xcbQ\xc5\x82.>\xe8\xa8\xaf\t\xc65\x91\x1fF\xae\x0c\xda\x1aD\x1f\xe7\xfbD\xc77\x82&%\xfbzJt\xf2\x9a\x08\x04\x9d.\xe8\xec\xcf\x02X\xab\x16\x0f?\x03M\xabA\xd1]>\x7f\x9eV\xecvv\xd7\xe1\xc5\x0e\xefg\x0f\x1d^b\xc9>\x93\xa0+\xfe\rV\x95m\xe3'

Restart...

sage: loads('x\x9cu\x8f\xbbN\x031\x10E\x958\x810\x10\x1e\x7f\x01\x8d\xa3\xe5\xf1\x0biVPX\xda2\xb2\x1c\xefd\xb1\xd6\xb13~D\xa2@\xa2A\xc0_\xb3\tK*\xe8\xce-\xce\x9d;oC\x1dU\x83|\xed\xebl1\xf2-\xea\xe4\x83\x0c*\x19\xef\x94\x955\xba\x88\x90\xdd\xc6\xe8\xd6\xa2\xdc\x16@\x83\xeb\x1f%\xa6\x90u\xca\x01\xf9J\xed\xa4\x17h\xd0a0Z\xf6Y\xfej@\xc3\x7f\x1d\xeb}\x9b7\xb2\xb1~\xa9,\x10\xab`\x1e\x10\x1f\xf7sh\xf4.h\\\x8e\xcbQ\xc5\x82.>\xe8\xa8\xaf\t\xc65\x91\x1fF\xae\x0c\xda\x1aD\x1f\xe7\xfbD\xc77\x82&%\xfbzJt\xf2\x9a\x08\x04\x9d.\xe8\xec\xcf\x02X\xab\x16\x0f?\x03M\xabA\xd1]>\x7f\x9eV\xecvv\xd7\xe1\xc5\x0e\xefg\x0f\x1d^b\xc9>\x93\xa0+\xfe\rV\x95m\xe3')
(1, 2/3, 4/5)
edit flag offensive delete link more

Comments

To clarify, the examples in the reference use `SAGE_TMP` so that Sage doesn't create nasty extra files while doctesting.

kcrisman gravatar imagekcrisman ( 2012-10-17 09:04:59 +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

Stats

Asked: 2012-10-17 05:11:55 +0100

Seen: 688 times

Last updated: Oct 17 '12