ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 22 Mar 2013 21:10:49 +0100sage_eval: invalid syntaxhttps://ask.sagemath.org/question/9931/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.Thu, 21 Mar 2013 16:00:24 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/Comment by kcrisman for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18027#post-id-18027@AndrewWin: You might find the `cmds` keyword to be useful; read the full `sage_eval?` documentation, I think you'll find the whole things what you need.Fri, 22 Mar 2013 21:10:49 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18027#post-id-18027Comment by kcrisman for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18028#post-id-18028@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.Fri, 22 Mar 2013 21:10:15 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18028#post-id-18028Comment by kcrisman for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18031#post-id-18031I 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.Fri, 22 Mar 2013 13:00:09 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18031#post-id-18031Comment by Bétréma for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18032#post-id-18032What's wrong with a simple assignment y=3, why do you need sage-eval ?Fri, 22 Mar 2013 09:04:54 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18032#post-id-18032Comment by AndreWin for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18029#post-id-18029I 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!Fri, 22 Mar 2013 13:29:00 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18029#post-id-18029Comment by Bétréma for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18030#post-id-18030@kcrisman 'y' is an input, not an output.Fri, 22 Mar 2013 13:07:41 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18030#post-id-18030Answer by kcrisman for <p>Hello!
I try in Sage 5.7 Notebook (localhost, not <a href="http://sagenb.org">sagenb.org</a>):</p>
<pre><code>sage_eval("y=3")
...
y=Integer(3)
^
SyntaxError: invalid syntax
</code></pre>
<p>What's wrong? Thanks.</p>
<p><strong>Upd</strong></p>
<pre><code> sage_eval(("y=3", "y"))
3
y
....
NameError: name 'y' is not defined
</code></pre>
<p>I want y was defined. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?answer=14671#post-id-14671 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
Thu, 21 Mar 2013 16:35:38 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?answer=14671#post-id-14671Comment by AndreWin for <pre><code>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
</code></pre>
<p><code>y=3</code> isn't a "thing", so you can't <code>sage_eval</code> it. Maybe you want this, though, also from the documentation.</p>
<pre><code>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
</code></pre>
<p>So you would have</p>
<pre><code>sage: sage_eval(('y=3','y'))
3
</code></pre>
https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18034#post-id-18034Thank you! Unfortunately it's not enough for me. I updated my question.Fri, 22 Mar 2013 01:07:36 +0100https://ask.sagemath.org/question/9931/sage_eval-invalid-syntax/?comment=18034#post-id-18034