ACBlue
ACBlue

Reputation: 113

Parsing an expression containing N using SymPy

I am parsing an expression using Sympy and getting the following trace:

>>> parse_expr("3N", transformations=transformations)`
TypeError: unsupported operand type(s) for *: 'Integer' and 'function'

From what I could gather, this happens because N is seen as a function by the parser and not simply as any other string. The code works fine with a few other symbols that I tested.

Can anyone explain briefly why this is happening? Is there a list of keywords or characters which cannot be parsed using parse_expr?

Upvotes: 3

Views: 352

Answers (1)

Matt
Matt

Reputation: 17629

Quoting from the docs (pitfalls and gotchas):

Lastly, it is recommended that you not use I, E, S, N, C, O, or Q for variable or symbol names, as those are used for ... numeric evaluation (N() is equivalent to evalf() )... Or better yet, always use lowercase letters for Symbol names. Python will not prevent you from overriding default SymPy names or functions, so be careful.

Upvotes: 3

Related Questions