On Sun, Apr 16, 2023 at 9:32 PM G. M.-S. <lists....@gmail.com> wrote:
>
>
> Is there a way to evaluate a string in the current scope?
>
> So that
> sage: expression
> and
> sage: some_evaluate(str(expression))
> give the same thing at the same place.
> I know about sage_eval, but it seems to need a dictionary of everything in 
> the local scope.
>
> For instance,
> sage: a=3
> sage: a^2
> 9
> sage: some_evaluate('a^2')
> 9
> instead of
> sage: a=3
> sage: sage_eval('a^2')
> NameError: name 'a' is not defined
> (of course this is a trivial example).

there is a plain eval():

sage: a=2
sage: eval("a^2")
0
sage: eval("a+a")
4
sage: eval("a**2")
4

(it looks like it doesn't do preparsing, but is the "normal" Python,
but it's a minor issue IMHO)

>
> Guillermo
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-support+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-support/CANnG18-6kgPsA1jZTKEZKsOVNxEpvRdMJi_xyv37r6po_r1fsw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAAWYfq0e%3D%2BM%2BKLd06cYL%3D95CTM53gc%3D67qGm%2BMrJ8ZZ9PNifEw%40mail.gmail.com.

Reply via email to