Usage of eval()

Does the Ignition scripting engine support eval()?

Here is an example of Python eval function. I get error in the script console when I execute this.

cmd = '''
print (55)
'''
eval(cmd)


Traceback (most recent call last):
  File "<input>", line 6, in <module>
  File "<string>", line 2
    print (55)
    ^
SyntaxError: no viable alternative at input 'print'

Yes, but, and I can't really understate this...

Don't use eval.

The error in your snippet is because Ignition's scripting environment is Jython, which uses Python 2 syntax. So print is a statement, not a function.

But, seriously:

Don't use eval.

Whatever thing you're trying to do, there's a better way to do it than eval. Guaranteed.

5 Likes

Hmmm. I'm a bad boy. My spreadsheet import tool runs it with user-supplied content.

But I agree, in general.