Thanks Dima.
I think that
sage: eval(preparse(string))
does what I need.

Guillermo

On Sun, 16 Apr 2023 at 23:45, Dima Pasechnik <dimp...@gmail.com> wrote:

> 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)
>

-- 
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/CANnG188WNXrtAr8zO9trRH%3D7Jzy0_s9bK5n%2BDehUhQ1ry%2BJ%3DUg%40mail.gmail.com.

Reply via email to