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.Fri, 11 May 2012 00:29:16 -0500How do I convert a notebook to a python script?http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/I'm asking this because I'm starting a project and Sage seems like a very good platform to do some prototyping.
Better yet, it might be a great way to use the code that results from my prototyping directly has the final version as well.
But for that to work with a minimal of hardship though, a few things would be usefull:
1. A way to grab the code content of a notebook and generate an independent python script or function
2. A list of libraries, with version, that every sage version uses.
3. An instalable library version of sage that could be imported from the script
4. Anything else that I'm missing and you know sage can do to help in this task
I'm not asking for a completely automatic way to do this, just for resources/scripts or general advices about how to do it.
I'm also just starting to look into sage so, don't assume to much on what I may know. ;)
Thanks.Sat, 10 Mar 2012 07:58:00 -0600http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/Comment by Alexandre Martins for <p>I'm asking this because I'm starting a project and Sage seems like a very good platform to do some prototyping.</p>
<p>Better yet, it might be a great way to use the code that results from my prototyping directly has the final version as well.</p>
<p>But for that to work with a minimal of hardship though, a few things would be usefull:</p>
<ol>
<li><p>A way to grab the code content of a notebook and generate an independent python script or function</p></li>
<li><p>A list of libraries, with version, that every sage version uses.</p></li>
<li><p>An instalable library version of sage that could be imported from the script</p></li>
<li><p>Anything else that I'm missing and you know sage can do to help in this task</p></li>
</ol>
<p>I'm not asking for a completely automatic way to do this, just for resources/scripts or general advices about how to do it.</p>
<p>I'm also just starting to look into sage so, don't assume to much on what I may know. ;)</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=19789#post-id-19789Both answers here are very usefull to me. I'm just taking a bit of time selecting a "right" answer because I haven't tried them yet in a big project.Fri, 11 May 2012 00:29:16 -0500http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=19789#post-id-19789Answer by Shashank for <p>I'm asking this because I'm starting a project and Sage seems like a very good platform to do some prototyping.</p>
<p>Better yet, it might be a great way to use the code that results from my prototyping directly has the final version as well.</p>
<p>But for that to work with a minimal of hardship though, a few things would be usefull:</p>
<ol>
<li><p>A way to grab the code content of a notebook and generate an independent python script or function</p></li>
<li><p>A list of libraries, with version, that every sage version uses.</p></li>
<li><p>An instalable library version of sage that could be imported from the script</p></li>
<li><p>Anything else that I'm missing and you know sage can do to help in this task</p></li>
</ol>
<p>I'm not asking for a completely automatic way to do this, just for resources/scripts or general advices about how to do it.</p>
<p>I'm also just starting to look into sage so, don't assume to much on what I may know. ;)</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?answer=13350#post-id-13350There are a couple of ways of doing this. You can write a pythonscript script and import the sage module. In order to use sage commands use the following line
from sage.all import *
In order to do this you need sage in you PYHTONPATH. You can make sure it does by starting your python script with
import sys
sys.path.append('path-to-sage')
A better alternative, which I use when I am trying to do what you are doing, is that I write the python script with 'from sage.all import *' on the first line and then use the python from sage to run it using the command
sage -python
This way you can use the python interpreter of sage.
Sat, 10 Mar 2012 11:28:30 -0600http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?answer=13350#post-id-13350Comment by Alexandre Martins for <p>There are a couple of ways of doing this. You can write a pythonscript script and import the sage module. In order to use sage commands use the following line</p>
<pre><code>from sage.all import *
</code></pre>
<p>In order to do this you need sage in you PYHTONPATH. You can make sure it does by starting your python script with</p>
<pre><code>import sys
sys.path.append('path-to-sage')
</code></pre>
<p>A better alternative, which I use when I am trying to do what you are doing, is that I write the python script with 'from sage.all import *' on the first line and then use the python from sage to run it using the command</p>
<pre><code>sage -python
</code></pre>
<p>This way you can use the python interpreter of sage.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=19790#post-id-19790@EviatarBach This is actually a nice approach to what I was asking. Not a complete answer but I wasn't expecting that since what I ask is a bit outside sage's use cases.Fri, 11 May 2012 00:27:17 -0500http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=19790#post-id-19790Comment by Shashank for <p>There are a couple of ways of doing this. You can write a pythonscript script and import the sage module. In order to use sage commands use the following line</p>
<pre><code>from sage.all import *
</code></pre>
<p>In order to do this you need sage in you PYHTONPATH. You can make sure it does by starting your python script with</p>
<pre><code>import sys
sys.path.append('path-to-sage')
</code></pre>
<p>A better alternative, which I use when I am trying to do what you are doing, is that I write the python script with 'from sage.all import *' on the first line and then use the python from sage to run it using the command</p>
<pre><code>sage -python
</code></pre>
<p>This way you can use the python interpreter of sage.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=20110#post-id-20110I was trying to answer point 1 and 3. I don't think the question was about how to copy paste the output.Sat, 17 Mar 2012 17:54:04 -0500http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=20110#post-id-20110Comment by Eviatar Bach for <p>There are a couple of ways of doing this. You can write a pythonscript script and import the sage module. In order to use sage commands use the following line</p>
<pre><code>from sage.all import *
</code></pre>
<p>In order to do this you need sage in you PYHTONPATH. You can make sure it does by starting your python script with</p>
<pre><code>import sys
sys.path.append('path-to-sage')
</code></pre>
<p>A better alternative, which I use when I am trying to do what you are doing, is that I write the python script with 'from sage.all import *' on the first line and then use the python from sage to run it using the command</p>
<pre><code>sage -python
</code></pre>
<p>This way you can use the python interpreter of sage.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=20111#post-id-20111I don't see how this answers the question.Sat, 17 Mar 2012 17:13:07 -0500http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?comment=20111#post-id-20111Answer by Eviatar Bach for <p>I'm asking this because I'm starting a project and Sage seems like a very good platform to do some prototyping.</p>
<p>Better yet, it might be a great way to use the code that results from my prototyping directly has the final version as well.</p>
<p>But for that to work with a minimal of hardship though, a few things would be usefull:</p>
<ol>
<li><p>A way to grab the code content of a notebook and generate an independent python script or function</p></li>
<li><p>A list of libraries, with version, that every sage version uses.</p></li>
<li><p>An instalable library version of sage that could be imported from the script</p></li>
<li><p>Anything else that I'm missing and you know sage can do to help in this task</p></li>
</ol>
<p>I'm not asking for a completely automatic way to do this, just for resources/scripts or general advices about how to do it.</p>
<p>I'm also just starting to look into sage so, don't assume to much on what I may know. ;)</p>
<p>Thanks.</p>
http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?answer=13373#post-id-13373Unfortunately, I don't think there's a direct way of doing this. However, you can click on the "Edit" tab on the top right of an open notebook. That will have all the code from that notebook, as well as the output. You can copy that, although you'll have to manually remove the output and the cell labels.Sat, 17 Mar 2012 17:18:27 -0500http://ask.sagemath.org/question/8782/how-do-i-convert-a-notebook-to-a-python-script/?answer=13373#post-id-13373