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.Sun, 08 Apr 2018 21:28:29 -0500Import Sage Worksheetshttp://ask.sagemath.org/question/41924/import-sage-worksheets/ 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
Sun, 08 Apr 2018 19:24:28 -0500http://ask.sagemath.org/question/41924/import-sage-worksheets/Answer by slelievre for <p>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 <code>attach</code> 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.</p>
<p><code>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</code></p>
<p>Can anyone help me with this issue? </p>
<p>Thanks,</p>
<p>Adam</p>
http://ask.sagemath.org/question/41924/import-sage-worksheets/?answer=41926#post-id-41926Once 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.sage`once, 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`.Sun, 08 Apr 2018 20:10:30 -0500http://ask.sagemath.org/question/41924/import-sage-worksheets/?answer=41926#post-id-41926Comment by slelievre for <p>Once you have a few functions you want to use and reuse, store them
in a file with extension <code>.sage</code>, for example <code>mycode.sage</code>.</p>
<p>Then, from a worksheet, you can either</p>
<pre><code>load /full/path/to/mycode.sage
</code></pre>
<p>which will load the code in <code>mycode.sage</code>once, or</p>
<pre><code>attach /full/path/to/mycode.sage
</code></pre>
<p>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.</p>
<p>Note that <code>/full/path/to/mycode.sage</code> should be replaced with
the actual full path to <code>mycode.sage</code>, for example
<code>/home/user/solving_the_riemann_hypothesis/mycode.sage</code> or
<code>/Users/Sagista/Documents/MySuperProject/mycode.sage</code>.</p>
http://ask.sagemath.org/question/41924/import-sage-worksheets/?comment=41935#post-id-41935Store 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).Sun, 08 Apr 2018 21:28:29 -0500http://ask.sagemath.org/question/41924/import-sage-worksheets/?comment=41935#post-id-41935Comment by ajmullins for <p>Once you have a few functions you want to use and reuse, store them
in a file with extension <code>.sage</code>, for example <code>mycode.sage</code>.</p>
<p>Then, from a worksheet, you can either</p>
<pre><code>load /full/path/to/mycode.sage
</code></pre>
<p>which will load the code in <code>mycode.sage</code>once, or</p>
<pre><code>attach /full/path/to/mycode.sage
</code></pre>
<p>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.</p>
<p>Note that <code>/full/path/to/mycode.sage</code> should be replaced with
the actual full path to <code>mycode.sage</code>, for example
<code>/home/user/solving_the_riemann_hypothesis/mycode.sage</code> or
<code>/Users/Sagista/Documents/MySuperProject/mycode.sage</code>.</p>
http://ask.sagemath.org/question/41924/import-sage-worksheets/?comment=41933#post-id-41933Is 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!
AdamSun, 08 Apr 2018 20:42:00 -0500http://ask.sagemath.org/question/41924/import-sage-worksheets/?comment=41933#post-id-41933