Ask Your Question

sage_eval: invalid syntax

asked 2013-03-21 16:00:24 +0200

AndreWin gravatar image

updated 2013-03-22 01:05:40 +0200

Hello! I try in Sage 5.7 Notebook (localhost, not

SyntaxError: invalid syntax

What's wrong? Thanks.


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

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

edit retag flag offensive close merge delete


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

Bétréma gravatar imageBétréma ( 2013-03-22 09:04:54 +0200 )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.

kcrisman gravatar imagekcrisman ( 2013-03-22 13:00:09 +0200 )edit

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

Bétréma gravatar imageBétréma ( 2013-03-22 13:07:41 +0200 )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!

AndreWin gravatar imageAndreWin ( 2013-03-22 13:29:00 +0200 )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.

kcrisman gravatar imagekcrisman ( 2013-03-22 21:10:15 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-03-21 16:35:38 +0200

kcrisman gravatar image
sage: sage_eval?
   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


   * "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)'))

So you would have

sage: sage_eval(('y=3','y'))
edit flag offensive delete link more


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

AndreWin gravatar imageAndreWin ( 2013-03-22 01:07:36 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-21 16:00:24 +0200

Seen: 2,566 times

Last updated: Mar 22 '13