1 | initial version |
I you are already used to some particular editor for coding, you can/should keep it, so that you will be at ease with it.
Now, if you want to store some functions in a file, you can use:
sage: %runfile('/path/to/file.sage')
and the file is run once, or
sage: attach('/path/to/file.sage')
and the file is re-run each time you save it (useful whant you want to test its parts while writing it).
If you name the file file.py
instead of file.sage
, then there will not be any Sage preparsing (e.g. ^
will not mean power
).
Now, if you want to import custom things as modules with the import
command, you can store your my_file.py
files in some my_directory
. But you should tell Sage that this directory contains interesting things for it as follows:
import sys
sys.path.append('/path/to/my_directory/')
Then you can do:
from my_file import my_function
If you want to automatically append my_directory
at Sage startup, you can do add the previous lines in the file $HOME/.sage/init.sage
2 | No.2 Revision |
I you are already used to some particular editor for coding, you can/should keep it, so that you will be at ease with it.
Now, if it (shortcuts, syntaxic coloration,...). What is worth noticing, is that there are tools to ease a "store things in files and use them in a Sage console" workflow, whatever your editor is.
If you want to store some functions in a file, file and use them in a Sage shell you can use:do:
sage: %runfile('/path/to/file.sage')
and the file is will be run once, or
sage: attach('/path/to/file.sage')
and the file is will be re-run each time you save it (useful whant you want to test its parts while writing it).
If you name the file file.py
instead of file.sage
, then there will not be any Sage preparsing (e.g. ^
will not mean power
).). Note that only .py
files are accepted in the Sage source code, so you should use them if you plan to insert your code as a part of Sage.
Now, if you want to import custom things functions/classes/variables as modules with the import
command, you can store your my_file.py
files in some my_directory
. But you should , and tell Sage that this directory contains interesting things for it as follows:
import sys
sys.path.append('/path/to/my_directory/')
Then you can do:
from my_file import my_function
If you want to automatically append my_directory
at Sage startup, you can do add the previous lines in the file $HOME/.sage/init.sage
3 | No.3 Revision |
I you are already used to some particular editor for coding, you can/should keep it, so that you will be at ease with it (shortcuts, syntaxic coloration,...). What is worth noticing, is that there are tools to ease a "store things in files and use them in a Sage console" workflow, whatever your editor is.
If you want to store some functions in a file and use them in a Sage shell you can do:
sage: %runfile('/path/to/file.sage')
and the file will be run once, or
sage: attach('/path/to/file.sage')
and the file will be re-run each time you save it (useful whant when you want to test its parts while writing modifying it).
If you name the file file.py
instead of file.sage
, then there will not be any Sage preparsing (e.g. ^
will not mean power
). Note that only .py
files are accepted in the Sage source code, so you should use them if you plan to insert your code as a part of Sage.
Now, if you want to import custom functions/classes/variables as modules with the import
command, you can store your my_file.py
files in some my_directory
, and tell Sage that this directory contains interesting things for it as follows:
import sys
sys.path.append('/path/to/my_directory/')
Then you can do:
from my_file import my_function
If you want to automatically append my_directory
at Sage startup, you can add the previous lines in the file $HOME/.sage/init.sage