On Thu, May 22, 2008 at 10:07 PM, mark mcclure <[EMAIL PROTECTED]> wrote:
>
> On May 7, 2:41 am, Amir <[EMAIL PROTECTED]> wrote:
>> Can I start a Sage session from C? I would need to pass commands, set
>> and get variables, and cleanly terminate the session. I would like to
>> do this as a mathlink module to call Sage from Mathematica.
>
> As a fan of both Sage and Mathematica, I found this to be an
> interesting question. For example, the graph theoretic
> tools in Sage, via Networkx and N.I.C.E., are generally
> better than those currently in Mathematica. The graph
> visualization seems to be better in Mathematica at this
> point. So it's nice to use the tools together. I've got a
> sample notebook that does a couple things like this here:
> http://facstaff.unca.edu/mcmcclur/Mathematica/Sage/
>
> It's pretty basic at the moment - mainly proof of concept,
> but it demonstrates a workable approach. The basic idea is
> to use Pythonika to access Sage via pexpect. I do have a
> question, as I'm fairly new to Python and Sage. I have
> several Python lines that look something like this:
>
> import pexpect
> child = pexpect.spawn('/Applications/sage/sage')"
> child.expect('.*')
> while child.after[-6:] != 'sage: ':
> child.expect('.*')
>
> The point behind the while statement is to continue
> reading until the next prompt is reached. I wonder
> how robust this is? Or whether there is a more
> standard approach?
Why don't you do
child.expect('sage: ')
Also, make sure you set
child.maxread
to something big like 10000 or so, since it will make things
100's of times faster than not doing that.
Take a look at
SAGE_ROOT/devel/sage/sage/interfaces/expect.py
and
SAGE_ROOT/devel/sage/sage/interfaces/sage0.py
for an example of a pexpect interface to Sage itself.
William
-- william
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---