SyntaxError on parse_expr

228 views
Skip to first unread message

Amit Saha

unread,
Jun 14, 2013, 9:45:51 PM6/14/13
to sy...@googlegroups.com
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

Aaron Meurer

unread,
Jun 14, 2013, 10:00:20 PM6/14/13
to sy...@googlegroups.com
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
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages