Hello Martin,

First of all, thank you very much for answering.

I solved my problem, inspecting the C codes generated by two versions of
Sage, when calling 'eval'.
It is now sufficient (and seemingly necessary), to pass the dictionary
returned by the 'globals ()' function to eval, in compiled functions.

Best,
François

2012/9/12 Martin Albrecht <[email protected]>

> Try this:
>
> sage: P.<a,b,c> = QQ[]
> sage: s = "2*a*b + c"
> sage: eval(s)
> 2*a*b + c
> sage: del a
> sage: del b
> sage: del c
> sage: eval(s)
> ---------------------------------------------------------------------------
> NameError                                 Traceback (most recent call last)
>
> /home/malb/<ipython console> in <module>()
>
> /home/malb/<string> in <module>()
>
> NameError: name 'a' is not defined
>
> sage: eval(s,P.gens_dict())
> 2*a*b + c
>
> See eval? about which parameters it accepts (globals and locals for global
> and
> local variables)
>
> On Wednesday 12 Sep 2012, François Boulier wrote:
> > Hi,
> >
> > I am posting again, for 5.3, the message I posted for 5.2
> >
> > I am developing a sage package which relies on a C library. The C library
> > returns expressions (polynomials) as strings.
> > I am looking for a simple way to convert these strings as Sage objects.
> > So far, I have been using expressions such as:
> >
> >     eval (preparse (the_string))
> >
> > It used to work in releases 4.7 and 4.8. Other users told me it worked in
> > 5.1.
> > Starting from 5.2, and now in 5.3, I am getting NameError(s) for the
> > variables which occur in the strings.
> > The same phenomenon is observed on at least two different platforms.
> > It seems that, in a compiled code, the eval function does not recognize
> > variables (the problem does not show up under the interpreter).
> >
> > Did I miss a change of specification of eval ? Is this a bug ?
> > Or am I using the wrong method ?
> >
> > Here is a simplified function which produces the error:
> >
> >     def toto (self, list L):
> >         cdef bytes L_as_string
> >         cdef list eqns
> >         L_as_string = bytes(L)
> >         eqns = eval (L_as_string)
> >         return eqns
> >
> > At runtime:
> >
> > boulier@ciney:~$
> > tmp/sage-5.3-linux-64bit-ubuntu_10.04.4_lts-x86_64-Linux/sage
> > ----------------------------------------------------------------------
> >
> > | Sage Version 5.3, Release Date: 2012-09-08                         |
> > | Type "notebook()" for the browser-based notebook interface.        |
> > | Type "help()" for help.                                            |
> >
> > ----------------------------------------------------------------------
> > Loading Sage library. Current Mercurial branch is: blad
> > sage: from sage.libs.blad.DifferentialAlgebra import DifferentialRing
> > sage: a,b = var ('a,b')
> > sage: y = function ('y')
> > sage: R = DifferentialRing (derivations = [a,b], blocks = [y])
> > sage: R.toto ([a])
> >
> ---------------------------------------------------------------------------
> > NameError                                 Traceback (most recent call
> last)
> >
> > /home/boulier/<ipython console> in <module>()
> >
> >
> /home/boulier/tmp/sage-5.3-linux-64bit-ubuntu_10.04.4_lts-x86_64-Linux/loca
> > l/lib/python2.7/site-packages/sage/libs/blad/DifferentialAlgebra.so in
> > sage.libs.blad.DifferentialAlgebra.DifferentialRing.toto
> > (sage/libs/blad/DifferentialAlgebra.c:8999)()
> >
> >
> /home/boulier/tmp/sage-5.3-linux-64bit-ubuntu_10.04.4_lts-x86_64-Linux/loca
> > l/lib/python2.7/site-packages/sage/libs/blad/DifferentialAlgebra.so in
> > <module>()
> >
> > NameError: name 'a' is not defined
> >
> > All the best,
> > François
>
> Cheers,
> Martin
>
> --
> name: Martin Albrecht
> _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
> _otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF
> _www: http://martinralbrecht.wordpress.com/
> _jab: [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/sage-devel?hl=en.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to