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.Sun, 11 Jan 2015 19:12:10 +0100Errors with sage_evalhttps://ask.sagemath.org/question/25461/errors-with-sage_eval/ Hello!
I try to use function <code>sage_eval</code> and It seems for me that either I found bug either I don't understand smth.
cmds = """
def somef():
return 443
res = somef()"""
sage_eval('res', cmds = cmds)
NameError: global name '_sage_const_443' is not defined
sage_eval('res', cmds="def somef(): return 443; res=somef()")
NameError: name 'res' is not defined.
Please give me some hints how to solve this problem. Thanks in advance.
Best regards, Andrei.Sat, 10 Jan 2015 09:26:01 +0100https://ask.sagemath.org/question/25461/errors-with-sage_eval/Answer by slelievre for <p>Hello!</p>
<p>I try to use function <code>sage_eval</code> and It seems for me that either I found bug either I don't understand smth.</p>
<pre><code>cmds = """
def somef():
return 443
res = somef()"""
sage_eval('res', cmds = cmds)
</code></pre>
<p>NameError: global name '_sage_const_443' is not defined</p>
<pre><code>sage_eval('res', cmds="def somef(): return 443; res=somef()")
</code></pre>
<p>NameError: name 'res' is not defined.</p>
<p>Please give me some hints how to solve this problem. Thanks in advance.</p>
<p>Best regards, Andrei.</p>
https://ask.sagemath.org/question/25461/errors-with-sage_eval/?answer=25478#post-id-25478It seems that 443 is not parsed properly in your first attempt (I don't really understand why; it might be a bug).
In any case, one way around that is the following:
sage: cmds = "def somef():\n return Integer(443r)\nres = somef()"
sage: sage_eval('res', cmds=cmds)
In your second attempt, both `return 443` and `res=somef()` are part of the definition of `somef`, so that `res` is not defined.
Sun, 11 Jan 2015 19:12:10 +0100https://ask.sagemath.org/question/25461/errors-with-sage_eval/?answer=25478#post-id-25478