I'm assuming you pasted the wrong thing. 2*x*x is correct syntax. That can be debated. Currently, parse_expr is an internal function. We don't actually have a user-level function for parsing, so it's what we've pointed people to for the advanced parsing features that have been implemented, but it does mean that the interface is not as nice as it could be (it also means that the inteface may change at any time).
Aaron Meurer On Fri, Jun 14, 2013 at 8:45 PM, Amit Saha <[email protected]> wrote: > Hello, > > I noticed that passing an invalid mathematical expression causes a > SyntaxError (Python exception). For eg: > >>>> parse_expr('2*x*x') > > results in: > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python3.3/site-packages/sympy/parsing/sympy_parser.py", > line 164, in parse_expr > expr = eval(code, global_dict, local_dict) # take local objects in > preference > File "<string>", line 1 > Integer (2 )*Symbol ('x' )*Symbol ('x' )+Integer (2 )Symbol ('x' ) > ^ > SyntaxError: invalid syntax > > > I also understand why, since we are basically 'eval' ing: > > "Integer (2 )*Symbol ('x' )*Symbol ('x' )+Integer (2 )Symbol ('x' )" > > Shouldn't this be raised as a separate exception class from SymPy (on > the lines of class sympy.parsing.sympy_tokenize.TokenError, for > example)? > > Best, > Amit. > > > -- > http://echorand.me > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
