Ask Your Question

Revision history [back]

Regarding the first error, it is fortunate that Sage does not preparse what is inside a string (if it was the case before 7.3, then it was a huge bug). If you want your code withing a string to be preparsed, just use the perparse Sage function, for example:

sage: var('a x')
(a, x)
sage: print eval(preparse('16*a^2*x^2'))
16*a^2*x^2

Regarding your second error, well, opr is indeed not defined.

Regarding the first error, it is fortunate that Sage does not preparse what is inside a string (if it was the case before 7.3, then it was a huge bug). If you want your code withing a string to be preparsed, just use the perparse Sage function, for example:

sage: var('a x')
(a, x)
sage: print eval(preparse('16*a^2*x^2'))
16*a^2*x^2

Regarding your second error, well, opr is indeed not defined.defined. Note that you have to pass some context to sage_eval:

sage: var('a x')
(a, x)
sage: sage_eval('16*a^2*x^2') 
NameError: name 'a' is not defined
sage: sage_eval('16*a^2*x^2', locals={'x':x,'a':a})
16*a^2*x^2

Regarding the first error, it is fortunate that Sage does not preparse what is inside a string (if it was the case before 7.3, then it was a huge bug). If you want your code withing a string to be preparsed, just use the perparsepreparse Sage function, for example:

sage: var('a x')
(a, x)
sage: print eval(preparse('16*a^2*x^2'))
16*a^2*x^2

Regarding your second error, well, opr is indeed not defined. Note that you have to pass some context to sage_eval:

sage: var('a x')
(a, x)
sage: sage_eval('16*a^2*x^2') 
NameError: name 'a' is not defined
sage: sage_eval('16*a^2*x^2', locals={'x':x,'a':a})
16*a^2*x^2