Ask Your Question
3

Load notebook .sws file into shell

asked 2014-07-30 00:59:02 -0500

god.one gravatar image

Hello everyone.

I used sagenb.org for a very long time and now I wanted to migrate all my files to my PC. Is there any possibilty to load the .sws files into the sage shell? Searching the web did not bring any answers.

Another question: what is the best substitution to a sws in the shell? Should I write my sage code in another editor and then run it in the sage shell (eg. write all def in a py file, load it anew in every session,...)?

Thanks in advance

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
1

answered 2014-07-30 04:13:25 -0500

FrédéricC gravatar image

For the second part of the question, I would advice to

  • write code in python files (such as sehrschoen.py) or in .sage files. The difference is that .sage files are preparsed, so that you can used exactly the same syntax as in the notebook (things like 4^4 or R.<x>=QQ[] that are not allowed in pure python). I prefer to use .py files, because it is this kind of files that form the source code of sage.

  • use the magic command %attach sehrschoen.py to attach this file to your session when you want. This is better than load, because every modification of the file triggers the reloading automatically.

edit flag offensive delete link more

Comments

Sehr schoen. I will try this. If there is no easy way to turn .sws files into .sage files, the old copy&paste will have to do it for now.

god.one gravatar imagegod.one ( 2014-07-30 05:10:09 -0500 )edit
1

answered 2014-07-30 09:38:09 -0500

niles gravatar image

updated 2014-07-30 09:38:47 -0500

The .sws format is actually .tar.bz2 -- a compressed directory containing the input and output for each cell. So you can uncompress it with the tar command to extract your original input into a .sage file. See

https://groups.google.com/forum/#!top...

and

http://ask.sagemath.org/question/7507...

Unfortunately I don't know of an automated tool to do this, but it should be reasonably straightforward.

edit flag offensive delete link more
0

answered 2014-08-01 20:33:45 -0500

kcrisman gravatar image

You could possibly use sage -sws2rst for partial automation. It creates a ReST document that should have Sage input/output blocks in it as a text file. You'd still have to extract those, or possibly just put triple quotes around all the text.

But I don't think there is an automated way to turn a worksheet into a .sage file, nor could there really be since most worksheets aren't meant to be run as scripts. At least, mine aren't - it would create a huge mess of things defined before or after other things!

edit flag offensive delete link more

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: 2014-07-30 00:59:02 -0500

Seen: 1,129 times

Last updated: Aug 01 '14