Ignition version: 8.1.39
I am creating a hard-coded dictionary on multiple lines and noticed a value was incorrect.
Then I realized I was missing an end quote, and that fixed the issue.
My question is: why did the designer environment not warn me of this issue?
I tried replicating this a few different ways and here is what I found:
- this applies in the script console
- this applies in project script modules
- this happens with single quotes
- this happens with double quotes
- finally, the only way I got an editor notification (red gutter bar) or execution exception ("SyntaxError" message) was when I tried to execute something in between the lines (see image below)
It looks like the interpreter was able to see a valid path with the dil['b'] = "b\ndil['c']= 'c"
but also executed the next line of code which gives you the c value.
It throws the error on the print
calls because there is a statement that actually breaks the lookup for the ' which would end the string.
This happens also with:
di1 = {}
di1['a']= 'a
di1['b']= 'b
di1['c']= 'c'
print dil
Sometimes interpreters do weird things in perfect storms.
The reason you don't see the gutter bar in the first picture is due to the way the code editor is doing its syntax test. Technically it is valid code since it detects the end '
Python is a weird language sometimes.
I recommend assigning static dictionaries like this but thats just me :
di1 = {
"a":"a",
"b":"b",
"c":"c"
}
1 Like
Ok, I figured something like that was going on. Thanks!
1 Like