None,Nan or NA as a return value

Not sure where this belongs in the forum, but as a new developer to ignition i found this interesting and now have questions.
Normally when using an object where there is "Null" data i would have expected "" or null as a return len()=0, however i got a "None" len()=4 return when something is not present.

  1. is this some sort of python thing?
  2. can an environment variable be set for this? to be what we want or what?

curious mind.

None is Python's null, but you need to provide more context as to where you're encountering this. It sounds like you ran len() on a string containing the value "None".


sure thing.
first place i found it was reading a string tag. editor says null and the [0].value of a tag gave me NONE

then intentionally i called a runquery() where a column contains null and used .getValueAt(x,y)

so i found this odd.. to say the least, and yes i was doing some error checking between a value of null as a return and then double checking is my return value had a len()=0 for sanity , which is how i stumbled onto this nugget..


Null is null is null.
Python just uses a special singleton object it calls None as the null value. Because Ignition is just embedding a Jython interpreter, we're subject to the same semantics. It's all the same (lack of) value.

len(None) would not work, by the way. The only way you get a length of 4 from null/None is if you're directly or indirectly coercing it into a string first.

i was actually str() to see what was happening with my data.
what i was looking to do was as follows:
->Get my Tag Data<-
tempgTraceLogName = system.tag.readBlocking("[default]gStn_100/gTraceLogName")[0].value
-> evaluate if the container was null <-
if len(tempgTraceLogName) == 0:
but that failed which is why i went after the str() of the tag thinking this was my issue....
so my question then is whats the proper "string" handler recommended to use when evaluating the error of TypeError: object of type 'NoneType' has no len() ??


Since None is a special singleton, you check whether a given value is null using the referential equality operator, is. So if myVariable is None:.

You never want to drive control flow from the string representation of anything besides literal strings. Python is object oriented. Take advantage.