# sage_eval: invalid syntax

Hello! I try in Sage 5.7 Notebook (localhost, not sagenb.org):

sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax


What's wrong? Thanks.

Upd

 sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined


I want y was defined. What should I do? Thanks.

edit retag close merge delete

What's wrong with a simple assignment y=3, why do you need sage-eval ?

( 2013-03-22 03:04:54 -0500 )edit

I don't understand what is going on. I just started a brand-new Sage session, typed this one-liner in, and got 3. Is there anything else you did? There shouldn't be a y coming out at all.

( 2013-03-22 07:00:09 -0500 )edit

@kcrisman 'y' is an input, not an output.

( 2013-03-22 07:07:41 -0500 )edit

I wanted to create function that solve equation and determine which parameter to be evaluated. For example at the input Python dictionary: {'F_zat':300, 'sigma_t':250, 'd3':'?'} Function should to determine d3. eq(F_zat, sigma_t, d3) = ... is also function input.... Unfortunately english isn't my native language and it's difficult to me to explain my task in english. But today I have solved this task so this question is closed. Thanks everybody for the help!

( 2013-03-22 07:29:00 -0500 )edit

@Bétréma: Ah, that was not clear from the formatting; I thought that was the whole output. Looks like sage_eval, presumably intentionally, doesn't alter the globals.

( 2013-03-22 15:10:15 -0500 )edit

Sort by » oldest newest most voted
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

more

Thank you! Unfortunately it's not enough for me. I updated my question.

( 2013-03-21 19:07:36 -0500 )edit