On Sat, 2022-01-08 at 23:27 -0800, Jonathan Thornburg wrote:
> what's the idiomatic way for some other piece of Sage source code to
> execute the contents of all of those files?  What I've been doing is
> to create another file (say 'setup.sage') which contains the lines
>   load('foo.sage')
>   load('bar.sage')
>   load('baz.sage')
> so that
>   load('setup.sage')
> (either at the interactive Sage prompt or in another source file) loads
> all the individual files.  This works fine apart from the un-helpful
> error messages when (not if, *when*) I have bugs in my code.  Is there
> a more idiomatic way?
> 
> 

Since you haven't received a better reply... as soon as my own code
starts to span multiple files, I stop thinking of it as a series of
commands to be fed to the sage interpreter, and instead start thinking
of it as a python program/library.

Globals are always tricky, but in your example I might define a
function

  def initialize_globals():
      ...

in foo.py so that whatever you consider to be the "main program" can
run e.g.

  from sage.all import *
  from foo import initialize_globals
  from baz import compute_stuff

  initialize_globals()
  result = compute_stuff()
  print(result)

Beware that you won't get preparsing this way, but otherwise, this more
or less allows you to write a well-structured python library using all
of the features of sage.


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/5749f24f69f613283789723539ae3b24f4b86976.camel%40orlitzky.com.

Reply via email to