Attaching Sage files to sage worksheets - DrXyzzy/cocalc GitHub Wiki
QUESTION: Is there a way to write functions in one worksheet, and then important them to another and use them there?
Not exactly, but you can write code in a .sage file, then load it into another worksheet as illustrated at
(1) Put code in a new file with extension ".sage", e.g., code.sage
(2) In a Sage worksheet or the terminal, run this: %attach code.sage
or attach("code.sage")
(3) Now all code in code.sage is available in your worksheet, and whenever it changes, it will get reloaded automatically.
(4) If you're using Jupyter, this is all broken (see https://github.com/sagemathinc/cocalc/issues/2916), but at least you can use load("code.sage")
instead.