Ask Your Question
1

Import Sage Worksheets

asked 2018-04-09 02:24:28 +0100

ajmullins gravatar image

updated 2018-10-14 12:03:04 +0100

FrédéricC gravatar image

Hello, I'm looking to be able to modulate my code in the Sage Math cloud. I've done some research on the topic and it seems that one could use the attach syntax to bring in the methods from another worksheet. Unfortunately I get the following error when I try to attach the sagews 'test' which is in the same folder as the worksheet I'm working in.

File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 3443, in attach raise IOError('did not find file %r to attach' % fname) IOError: did not find file 'test' to attach

Can anyone help me with this issue?

Thanks,

Adam

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2018-04-09 03:10:30 +0100

slelievre gravatar image

Once you have a few functions you want to use and reuse, store them in a file with extension .sage, for example mycode.sage.

Then, from a worksheet, you can either

load /full/path/to/mycode.sage

which will load the code in mycode.sageonce, or

attach /full/path/to/mycode.sage

which will load it, and monitor the file so that each time any changes to the file are saved to disk, it gets loaded again.

Note that /full/path/to/mycode.sage should be replaced with the actual full path to mycode.sage, for example /home/user/solving_the_riemann_hypothesis/mycode.sage or /Users/Sagista/Documents/MySuperProject/mycode.sage.

edit flag offensive delete link more

Comments

Is this possible to utilize in the cloud only? The project I'm working on is collaborative with 2 other individuals, and in the future, many more. I would like to be able to import worksheets that are saved in the cloud, not on my hard drive. Thank you for the speedy response!

Adam

ajmullins gravatar imageajmullins ( 2018-04-09 03:42:00 +0100 )edit

Store the code you find useful in text files with extension .sage.

Many times one develops in a worksheet, the thing is to then extract all the functions that are general and can be reused elsewhere, and store them in a text file with extension .sage.

Using such a file, with load or attach should work in all settings: on your computer, on CoCalc, using Sage from the terminal, in the SageNB notebook, in a Jupyter notebook, in a CoCalc worksheet...

If you want to share more widely, the next step is to create a Python package containing your code, and to upload it to PyPI. Then people can install it in a simple standard way:

sage --pip install flipper

(replacing flipper by the name of your package once it's on PyPI).

slelievre gravatar imageslelievre ( 2018-04-09 04:28:29 +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: 2018-04-09 02:24:28 +0100

Seen: 1,003 times

Last updated: Apr 09 '18