ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 28 Jun 2011 17:07:47 +0200reuse scripts in Sage-NBhttps://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/Hi!
I have some existing Python scripts and data on a machine with Sage-NB running. The Python script takes in the data file as the argument. Is there a way to use them in the Sage-NB interface?
Thanks,Tue, 28 Jun 2011 15:49:43 +0200https://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/Answer by kcrisman for <p>Hi!</p>
<p>I have some existing Python scripts and data on a machine with Sage-NB running. The Python script takes in the data file as the argument. Is there a way to use them in the Sage-NB interface?</p>
<p>Thanks,</p>
https://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/?answer=12473#post-id-12473This is really easy, I'm pleased as punch that this actually works, I'd never tried it.
- Create a file. I made foo.sage, whose entire content is `g(x)=x^2`. I put it in my home directory.
- Do `load("~/foo.sage")`, or whatever is appropriate for where your script lives.
- Enjoy!
This should work with .py files as well. It's conceivable that you'll need appropriate permissions, etc.
If you have custom data to use as well, the best thing to do is see if the `DATA` variable will do what you need. This is documented in the "Help" link at the top of the notebook, and it should be pretty easy to upload an appropriate data file there as need be.Tue, 28 Jun 2011 16:15:10 +0200https://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/?answer=12473#post-id-12473Comment by riemann for <p>This is really easy, I'm pleased as punch that this actually works, I'd never tried it.</p>
<ul>
<li>Create a file. I made foo.sage, whose entire content is <code>g(x)=x^2</code>. I put it in my home directory.</li>
<li>Do <code>load("~/foo.sage")</code>, or whatever is appropriate for where your script lives.</li>
<li>Enjoy!</li>
</ul>
<p>This should work with .py files as well. It's conceivable that you'll need appropriate permissions, etc. </p>
<p>If you have custom data to use as well, the best thing to do is see if the <code>DATA</code> variable will do what you need. This is documented in the "Help" link at the top of the notebook, and it should be pretty easy to upload an appropriate data file there as need be.</p>
https://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/?comment=21536#post-id-21536Thanks, it's much easier than I thought. That does work for all the *.py files and the data. Thanks for the help!Tue, 28 Jun 2011 17:07:47 +0200https://ask.sagemath.org/question/8196/reuse-scripts-in-sage-nb/?comment=21536#post-id-21536