Invalid Token

Posted on
Sun Aug 06, 2017 8:14 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Invalid Token

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 ?

Posted on
Sun Aug 06, 2017 8:24 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Invalid Token

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?

Image

Posted on
Mon Aug 07, 2017 2:21 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Invalid Token

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.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Aug 09, 2017 6:40 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Invalid Token

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

Posted on
Thu Aug 10, 2017 9:05 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Invalid Token

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Aug 10, 2017 9:07 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Invalid Token

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).

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Aug 10, 2017 2:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Invalid Token

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... :(

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Aug 10, 2017 2:10 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Invalid Token

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.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Aug 13, 2017 10:49 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Invalid Token

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..

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests