More specific parsing error?

21 views
Skip to first unread message

Amit Saha

unread,
Apr 22, 2014, 4:04:39 PM4/22/14
to sy...@googlegroups.com
Hello,

Consider the following:

>>> expr=input('Enter a mathematical expression: ')

Enter a mathematical expression: x**2 + 3x + x**3 + 2x

>>> expr = sympify(expr)

Traceback (most recent call last):

File "<pyshell#146>", line 1, in <module>

expr = sympify(expr)

File "/usr/lib/python3.3/site-packages/sympy/core/sympify.py", line
180, in sympify

raise SympifyError('could not parse %r' % a)

sympy.core.sympify.SympifyError: SympifyError: "could not parse 'x**2
+ 3x + x**3 + 2x'"


Is it possible to get a more specific error message here? Like which
of the terms are invalid, for example?

Thanks,
Amit.


--
http://echorand.me

Aaron Meurer

unread,
May 7, 2014, 6:08:22 PM5/7/14
to sy...@googlegroups.com
Try using parse_expr from sympy.parsing.sympy_parser.

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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CANODV3kj5wSJPX4NhtGTkHVmNzn7fe4XSwnFo95PFJ2pTZ8r6w%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages