Ask Your Question
1

sage_eval: invalid syntax

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

AndreWin gravatar image

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

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 flag offensive close merge delete

Comments

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 +0100 )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 +0100 )edit

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

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

1 Answer

Sort by » oldest newest most voted
2

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

kcrisman gravatar image
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
edit flag offensive delete link more

Comments

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

AndreWin gravatar imageAndreWin ( 2013-03-22 01:07:36 +0100 )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

Stats

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

Seen: 2,730 times

Last updated: Mar 22 '13