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.Sun, 26 Dec 2021 17:18:41 +0100importing .ipynb notebooks in Sagemath 9.4https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/Following https://stackoverflow.com/questions/44116194/import-a-function-from-another-ipynb-file
Python/Sagemath9.4/Jupyter error?
Using jupyter with kernel selections:sagemath9.4, python3
I found that the import works if the file pyt.ipynb is written with the Jupyter kernel Python3 selected, but can't be read if it's written from Sagemath9.4 kernel.
Is there a more correct way or is it a bug?
File pyt.ipynb to be imported
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
File for importing
from ipynb.fs.full.pyt import *
testing = factorial(5)
testing
Here is the "diff" output, comparing the python3 save and the sagemath9.4 save
diff pyt.ipynb pyt-python.ipynb
< "display_name": "SageMath 9.4",
< "language": "sage",
< "name": "sagemath"
'> "display_name": "Python 3",
'> "language": "python",
'> "name": "python3"Sun, 26 Dec 2021 01:16:52 +0100https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/Comment by rrogers for <p>Following <a href="https://stackoverflow.com/questions/44116194/import-a-function-from-another-ipynb-file">https://stackoverflow.com/questions/4...</a>
Python/Sagemath9.4/Jupyter error? <br>
Using jupyter with kernel selections:sagemath9.4, python3 <br>
I found that the import works if the file pyt.ipynb is written with the Jupyter kernel Python3 selected, but can't be read if it's written from Sagemath9.4 kernel. <br>
Is there a more correct way or is it a bug? <br>
File pyt.ipynb to be imported</p>
<pre><code>def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
</code></pre>
<p>File for importing</p>
<pre><code>from ipynb.fs.full.pyt import *
testing = factorial(5)
testing
</code></pre>
<p>Here is the "diff" output, comparing the python3 save and the sagemath9.4 save <br>
diff pyt.ipynb pyt-python.ipynb </p>
<p>< "display_name": "SageMath 9.4", <br>
< "language": "sage", <br>
< "name": "sagemath" </p>
<p>'> "display_name": "Python 3", <br>
'> "language": "python", <br>
'> "name": "python3"</p>
https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/?comment=60453#post-id-60453Thanks, I will post it there. Perhaps an MI program would be useful to navigate the labyrinth of help sites; for the future :) Upon thinking about it; for other users I think I will leave this question up.Sun, 26 Dec 2021 17:18:41 +0100https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/?comment=60453#post-id-60453Comment by Emmanuel Charpentier for <p>Following <a href="https://stackoverflow.com/questions/44116194/import-a-function-from-another-ipynb-file">https://stackoverflow.com/questions/4...</a>
Python/Sagemath9.4/Jupyter error? <br>
Using jupyter with kernel selections:sagemath9.4, python3 <br>
I found that the import works if the file pyt.ipynb is written with the Jupyter kernel Python3 selected, but can't be read if it's written from Sagemath9.4 kernel. <br>
Is there a more correct way or is it a bug? <br>
File pyt.ipynb to be imported</p>
<pre><code>def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
</code></pre>
<p>File for importing</p>
<pre><code>from ipynb.fs.full.pyt import *
testing = factorial(5)
testing
</code></pre>
<p>Here is the "diff" output, comparing the python3 save and the sagemath9.4 save <br>
diff pyt.ipynb pyt-python.ipynb </p>
<p>< "display_name": "SageMath 9.4", <br>
< "language": "sage", <br>
< "name": "sagemath" </p>
<p>'> "display_name": "Python 3", <br>
'> "language": "python", <br>
'> "name": "python3"</p>
https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/?comment=60448#post-id-60448This question is relative to a Python [module] not part of Sage nor part of a standard Python distribution, and should be asked on the module's [issues page](https://github.com/ipython/ipynb/issues) with better chance of getting an answer.Sun, 26 Dec 2021 08:31:17 +0100https://ask.sagemath.org/question/60443/importing-ipynb-notebooks-in-sagemath-94/?comment=60448#post-id-60448