Ask Your Question

Is it possible to define commands permanently ?

asked 2022-08-28 20:43:22 +0100

Busterbie gravatar image

updated 2022-08-29 09:22:18 +0100

FrédéricC gravatar image

Hi! Just got started with Sage.

Alot of commands in Sage are quite verbose and long like "numerical_approx" or "cartesian_product". This might make things more accesible, but it does make the workflow quite slow and cluttered IMO. Is it possible to define new commands in Sage that will always be loaded everytime i open the console? Really i'm just trying to create permanent shorthand versions of existing commands.

In a less ideal, but still suitable solution: Is it possible to make a library that you can then load in the console? Then i could just load it everytime i start the console with one line of code.

Kind regards Buster

edit retag flag offensive close merge delete


In addition to adding commands in init.sage, I recommend using the TAB key frequently. You rarely need to type in the whole command. Also, the latest beta release (and so upcoming in an official release) includes an upgraded version of IPython, giving access to its "autosuggestions":

John Palmieri gravatar imageJohn Palmieri ( 2022-08-28 23:35:43 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2022-08-28 22:39:28 +0100

tmonteil gravatar image

updated 2022-08-28 22:40:33 +0100

Yes, you can put the command in the file named init.sage within the ~/.sage/ directory (where ~ is your home directory).

If you want to load a file, you can use %load file.sage in the Sage console (or jupyer notebook).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2022-08-28 20:43:22 +0100

Seen: 53 times

Last updated: Aug 29