Page 1 of 1
Invalid Token
Posted:
Sun Aug 06, 2017 8:14 pm
by jltnol
So I'm not the best at Python, but the following error came up and I'm not sure why..
If the SceneON is listed as
- Code: Select all
indigo.insteon.sendSceneOn(7)
it won't run, but will if listed as
- Code: Select all
indigo.insteon.sendSceneOn(07)
However this DOESN'T run
- Code: Select all
indigo.insteon.sendSceneOn(08)
but
- Code: Select all
indigo.insteon.sendSceneOn(8)
does.
The error I got was
Script Error embedded script: invalid token
Script Error around line 6 - "indigo.actionGroup.execute(1541175388),indigo.insteon.sendSceneOff(08)"I'm not going to loose any sleep over this but was more curious as to why one has to be formatted WITH the preceding zero, and the other doesn't....
Any ideas ?
Re: Invalid Token
Posted:
Sun Aug 06, 2017 8:24 pm
by matt (support)
I don't think the prefix 0 is the problem. From the look of the error message, it looks like there might be a formatting problem with your script. It looks like Indigo doesn't think there is a line break between the action group execution line and the insteon sendSceneOff line?
Re: Invalid Token
Posted:
Mon Aug 07, 2017 2:21 am
by FlyingDiver
Another issue to be aware of is that in Python 2.7, a leading zero indicates an octal integer. So 07 is legal, 08 is not.
Re: Invalid Token
Posted:
Wed Aug 09, 2017 6:40 pm
by jltnol
FWIW, I actually just coped the 1st line and pasted into the "else:" option, and changed the scene # to 08, and got the same error message... changing it from "08" to just "8" makes the error message go away... Likewise, changing the 1st line from "07" to "08" introduced the same error message... but going to just "8" made it go away.
- Code: Select all
dev = indigo.devices[120542152] # "KeypadLinc"
if (dev.ledStates[2] == True):
indigo.actionGroup.execute(339158514), indigo.insteon.sendSceneOn(07)
else:
indigo.actionGroup.execute(339158514), indigo.insteon.sendSceneOn(08
Re: Invalid Token
Posted:
Thu Aug 10, 2017 9:05 am
by jay (support)
It's the octal specifier mentioned by FlyingDiver above. Literals that start with a zero are interpreted as octal values and 08 is an invalid octal number.
Re: Invalid Token
Posted:
Thu Aug 10, 2017 9:07 am
by FlyingDiver
jay (support) wrote:It's the octal specifier mentioned by FlyingDiver above. Literals that start with a zero are interpreted as octal values and 08 is an invalid octal number.
Note that this is Python 2.x only. Which Indigo uses. Python 3 requires the use of the "0o" or "0O" prefix (zero-Oh).
Re: Invalid Token
Posted:
Thu Aug 10, 2017 2:09 pm
by jay (support)
IMO, it was a terrible idea in Python 2.x to do that. The Python 3 way is much better.
Unfortunately, I believe it's still in Python 3 for backwards compatibility...
Re: Invalid Token
Posted:
Thu Aug 10, 2017 2:10 pm
by FlyingDiver
jay (support) wrote:Unfortunately, I believe it's still in Python 3 for backwards compatibility...
Other way around, I think. 2 would take either, 3 will only take "0o". The leading zero was a nod towards a number of other languages which do the same thing. I think it started with C.
Re: Invalid Token
Posted:
Sun Aug 13, 2017 10:49 am
by jltnol
From a non-coder point of view, I do find it amusing that sometimes the simplest things are complicated... In the end, this was an easy hurdle for me to get over as I knew that the code worked in some instances. Past that, it was just a matter of experimenting 'til I came up with the right answer, and there were only 2 options... , but can easily understand that others my find this maddening..