Are Variable Values Case Sensitive?

Posted on
Mon Dec 07, 2015 8:38 pm
CraigM offline
Posts: 578
Joined: Oct 28, 2007

Are Variable Values Case Sensitive?

Are Variable Values Case Sensitive?

Posted on
Mon Dec 07, 2015 9:54 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Are Variable Values Case Sensitive?

The short answer: Yes, they are.

The long answer: I have created a variable called "Foo01" and set the value of that variable to "Bar". Consider the following script:

Code: Select all
x = indigo.variables['Foo01'].value

if x == "bar":
    indigo.server.log(u"Equal.")
else:
    indigo.server.log(u"Not equal.")

If you run it, you will get:
Code: Select all
Dec 7, 2015, 9:37:35 PM
  Script                          Not equal.

"bar" does not equal "Bar".

But an interesting thing is the difference between "==" and "is". Consider this:
Code: Select all
x = "Foo"
y = ''.join(["F", "o", "o"])

indigo.server.log(x)
if x == y:
   indigo.server.log(u"Equal.")
else:
    indigo.server.log(u"Not equal.")

indigo.server.log(y)
if x is y:
   indigo.server.log(u"Equal.")
else:
    indigo.server.log(u"Not equal.")


Will give you:
Code: Select all
  Script                          Foo
  Script                          Equal.
  Script                          Foo
  Script                          Not equal.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Dec 07, 2015 10:55 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Are Variable Values Case Sensitive?

But an interesting thing is the difference between "==" and "is". Consider this:

I am pretty sure Python works the same way as the other languages I know better in that the == is a comparison on value where in "is" would be used as a comparison on objects (i.e. are two objects in memory the same object). Some languages optimize this for non-object types such as integers and they will return the same result. Still, when attempting to check the value of a variable I would suggest sticking to the == construct.

Posted on
Tue Dec 08, 2015 4:52 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Are Variable Values Case Sensitive?

RogueProeliator wrote:
Still, when attempting to check the value of a variable I would suggest sticking to the == construct.

Adam makes a good point that I should have put in my post. It's almost always better to use the "==" comparator when checking the value of a variable.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Dec 08, 2015 9:59 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Are Variable Values Case Sensitive?

And, just to complete the thought, to ignore case in the comparison:

Code: Select all
x = indigo.variables['Foo01'].value

if x.lower() == "bar":
    indigo.server.log(u"Equal.")
else:
    indigo.server.log(u"Not equal.")


This will work for most people, but if you're using a different character set it's less reliable.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Dec 10, 2015 12:52 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Are Variable Values Case Sensitive?

Cool, came across a problem at weekend with upper/lower matching - that's a good snippet to use.


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests