5.2.2 Using the Command Line and a File

  1. Create a file hello.spyx.
  2. Put the following in it:
    def hello(name):
        """
        Print hello with the given name. 
        """
        print("Hello %s"%name)
    
  3. Start the Sage command-line interpreter and load the spyx file (this will fail if you do not have a C compiler installed).
    sage: load "hello.spyx"
    Compiling hello.spyx...
    sage: hello('World')
    Hello World
    
Note that you can change hello.spyx, then load it again and it will be recompiled on the fly. You can also attach hello.spyx so it is reloaded whenever you make changes.
sage: attach "hello.spyx"

See About this document... for information on suggesting changes.