Ask Your Question

Revision history [back]

There is no simple solution with the Sage notebook. You can save your worksheet as an .sws file and then from the command line do sage -sws2rst your_worksheet.sws to get an rst file, so that it is easier to post-process the text file to obtain a genuine Python file (this can then easily be done sine you just have to select lines that start either with <space><space><space><space>sage:<space> or with <space><space><space><space>...<space><space>).

It is easier with the jupyter notebook:

  • If you want a short notebook, you can clean all output by clicking on "Kernel" then "Restart & clear output". Then you can save your worksheet that only contains input cells (the cells with your code).
  • You can also get those input cells in a Python file by clicking on "Flie", then "Download as", then "Python (.py)".

There is no simple solution with the Sage notebook. You can save your worksheet as an .sws file and then from the command line do sage -sws2rst your_worksheet.sws to get an rst file, so that it is easier to post-process the text file to obtain a genuine Python file (this can then easily be done sine since you just have to select lines that start either with <space><space><space><space>sage:<space> or with <space><space><space><space>...<space><space>).

It is easier with the jupyter notebook:

  • If you want a short notebook, you can clean all output by clicking on "Kernel" then "Restart & clear output". Then you can save your worksheet that only contains input cells (the cells with your code).
  • You can also get those input cells in a Python file by clicking on "Flie", then "Download as", then "Python (.py)".