Mike, worked great.  If you are ever near Colorado Springs you have a
free lunch.

On Jun 23, 3:07 pm, Mike Hansen <[email protected]> wrote:
> Hi,
>
> On Tue, Jun 23, 2009 at 1:33 PM, Mikie<[email protected]> wrote:
> > The values are coming in as strings and I am converting them to
> > calculus type.  It is kind of working, but when I put 2*x^2-x or
> > 2*x**2-x I get "not a valid Python identifier.  What is real strange
> > is If I put
> > "x-2*x^2" it works.
> > Is there anyway to get the Sage preparser to work in the Python
> > script.
>
> Your best bet for that type of thing is to pass the string into SR
> which will parse the expression.
>
> sage: SR('2*x^2-x')
> 2*x^2 - x
> sage: SR('2*x**2-x')
> 2*x^2 - x
> sage: SR('x-2*x^2')
> -2*x^2 + x
>
> To access the preparser, you can do something like:
>
> sage: sage.misc.preparser.preparse('x^2')
> 'x**Integer(2)'
>
> Note that you get a string back.  You need to eval() that to get an
> object back.  Note that there are security risks using eval().  That's
> why it's safer to use the parser in SR.
>
> --Mike
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to