Ask Your Question

Revision history [back]

  1. Yes, it is easy to save and load Sage objects across worksheets, and outside worksheets (in command-line mode for instance). Sage objects are saved in .sobj files.

  2. You can load an object using either a url to the sage object file, or the file's full path. Now all we need is to either (a) save the file to a chosen location, or (b) understand where the file gets saved by default. Here are several options to achieve (a) and (b).

  3. You can specify a full path, instead of just a name, when saving your object. For instance,

    save(myvar,"/Users/me/Desktop/myvar.sobj")
    

    will save it on your desktop (adapt the path to your system if necessary).

  4. If, as in your example, you just type

    save(myvar,"myvar")
    

    in a notebook cell and evaluate the cell, the Sage object myvar gets saved as myvar.sobj somewhere.

    You probably noticed a link 'myvar.sobj' just below the worksheet cell with your save instruction. Click on that link and your browser will offer you to save the file myvar.sobj to the location of your choice. You can also right-click this link and choose 'Save link target as...' and pick a location to save it.

  5. The above-described right-click will also let you 'Copy link url'. Then, just paste the url to check the url to your file. The url you get should look like

    http://localhost:8080/home/admin/336/cells/2/myvar.sobj
    

    (in this example, I was using worksheet number 336 in my Sage notebook, and saved the object from cell number 2). You can then use this url to load your file.

  6. From the url above, you can also figure out the path to the file in your filesystem, which is somewhere in your your .sage folder. A little exploration reveals your file is at

    /Users/me/.sage/sage_notebook.sagenb/home/admin/336/cells/2/myvar.sobj
    

    (possibly slightly different depending on your system and Sage version). You can use this full path to load the object in another worksheet.

  7. You can find some examples of use of save and load by using the built-in help: type

    save?
    

    or

    load?
    

in Sage. The examples in the documentation for save show some nice tricks, such as: giving a short name to the string that will contain the url or the file's full path; using os.path.join to concatenate the path to a directory and a filename (adds slashes as appropriate); using SAGE_TMP to save the file in a temporary location (gets cleaned up regularly, good for stuff you don't want to keep long-term).

  1. Yes, it is easy to save and load Sage objects across worksheets, and outside worksheets (in command-line mode for instance). Sage objects are saved in .sobj files.

  2. You can load an object using either a url to the sage object file, or the file's full path. Now all we need is to either (a) save the file to a chosen location, or (b) understand where the file gets saved by default. Here are several options to achieve (a) and (b).

  3. You can specify a full path, instead of just a name, when saving your object. For instance,

    save(myvar,"/Users/me/Desktop/myvar.sobj")
    

    will save it on your desktop (adapt the path to your system if necessary).

  4. If, as in your example, you just type

    save(myvar,"myvar")
    

    in a notebook cell and evaluate the cell, the Sage object myvar gets saved as myvar.sobj somewhere.

    You probably noticed a link 'myvar.sobj' just below the worksheet cell with your save instruction. Click on that link and your browser will offer you to save the file myvar.sobj to the location of your choice. You can also right-click this link and choose 'Save link target as...' and pick a location to save it.

  5. The above-described right-click will also let you 'Copy link url'. Then, just paste the url to check the url to your file. The url you get should look like

    http://localhost:8080/home/admin/336/cells/2/myvar.sobj
    

    (in this example, I was using worksheet number 336 in my Sage notebook, and saved the object from cell number 2). You can then use this url to load your file.

  6. From the url above, you can also figure out the path to the file in your filesystem, which is somewhere in your your .sage folder. A little exploration reveals your file is at

    /Users/me/.sage/sage_notebook.sagenb/home/admin/336/cells/2/myvar.sobj
    

    (possibly slightly different depending on your system and Sage version). You can use this full path to load the object in another worksheet.

  7. You can find some examples of use of save and load by using the built-in help: type

    save?
    

    or

    load?
    

in Sage. The examples in the documentation for save show some nice tricks, such as: giving a short name to the string that will contain the url or the file's full path; using os.path.join to concatenate the path to a directory and a filename (adds slashes as appropriate); using SAGE_TMP to save the file in a temporary location (gets cleaned up regularly, good for stuff you don't want to keep long-term).