Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
sage: sage_eval?
<snip>
   Obtain a Sage object from the input string by evaluating it using
   Sage. This means calling eval after preparsing and with globals
   equal to everything included in the scope of "from sage.all import
   *".).

   INPUT:

   * "source" - a string or object with a _sage_ method

y=3 isn't a "thing", so you can't sage_eval it. Maybe you want this, though, also from the documentation.

You can also specify the object to evaluate as a tuple. A 2-tuple
is assumed to be a pair of a command sequence and an expression; a
3-tuple is assumed to be a triple of a command sequence, an
expression, and a dictionary holding local variables. (In this
case, the given dictionary will not be modified by assignments in
the commands.)

::

    sage: sage_eval(('f(x) = x^2', 'f(3)'))
    9

So you would have

sage: sage_eval(('y=3','y'))
3