On Jul 8, 5:45 am, TianWei <ltwis...@gmail.com> wrote: > > I built a worksheet with several cells in the notebook, and then > > wanted to try to run it on a remote computer using the command line > > interface. But I could not find a convincing way to export the > > worksheet to a simple text file that I could import directly to sage, > > i.e. a "something.sage" file. > > In the end, I had to copy and paste each cell separately into a text > > file on the remote machine, which I then imported with "load > > something.sage" But this is clearly not a reasonable solution for a > > long worksheet. > > I tried the "Text" option in the worksheet, but that produced output > > which I could not just copy straight into the sage command line, or > > import with "load". > > If Sage has an easy, automatic way of doing this, I'm not aware of it. > However, there's a couple ways to accomplish what you want to do > without doing a bunch of repetitive actions (for example, manually > copying out each the text cell). Unfortunately, both of my suggestions > require a bit of work: > > (1) Open the worksheet through the notebook interface, then click on > the "Text" tab. Copy the text there, then write a little script to > strip out every line that doesn't begin with "sage: ". The lines that > have "sage: " prepended are lines in the input cells (assuming you > didn't type "sage: " somewhere in the worksheet itself). Strip out the > "sage: " text.
OK, this is the idea that I came up with. It is also necessary to strip out the "..." that come at the start of indented lines, the <html> lines corresponding to the pretty-printed output, etc. I guess I just assumed that this must already have been done and be easily accessible, since it seems like a reasonably obvious thing to want to do -- use the nice notebook interface to create a document, and then convert it to plain Python and/or Sage to use for whatever. > > (2) You could tinker around with Notebook, Worksheet, and Cell objects > in Sage (using a script, command-line, or notebook interface). In > summary, you could create a Notebook object; get the desired Worksheet > object using one of the methods of the Notebook object; get a list of > Cell objects from the Worksheet; then pull out the input text from > each Cell object. The documentation for these objects are: > > http://www.sagemath.org/doc/reference/sagenb/notebook/notebook.htmlhttp://www.sagemath.org/doc/reference/sagenb/notebook/worksheet.htmlhttp://www.sagemath.org/doc/reference/sagenb/notebook/cell.html > > Again, I'm (obviously) not aware of a cleaner way to just pull out the > input text from a worksheet, and these two suggestions are just the > work-arounds I could think of. Thanks to all for the suggestions. David. > > As a side-note, the inverse process (converting from plain-text > commands to a sage worksheet) is easy; just upload it through the > notebook interface. > > -- Tianwei -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org