String Array Tag Read Fallback

I've scripted a read from a string array tag using a tag path parameter to the function. I want to define the behavior when the tag path is empty or none.

So, how do I assign an empty string array to the same variable, in place of the string array read from the tag?

When I read from the tag I get this:

array(java.lang.String, [u'e00002_Test', u'e00002_Test', u'e00002_Test', u'e00002_Test', u'e00002_Test', u'e00002_Test'])

and I want this for the empty/none result:

array(java.lang.String, [])

How do I do that with python? - or do I need an empty string array tag to read? Or, should I just use it as a list/dataset for scripting and update my code accordingly?

So you have a function that looks kinda like this:

def read_tag(tag_path):
    string_array = system.tag.readBlocking([tag_path])[0].value
    data = do_stuff_with_the_array()
    return data

And you want to handle the case where tag_path is None ?

Feels like this should be enough:

def read_tag(tag_path):
    if tag_path is None:
        return []
    string_array = system.tag.readBlocking([tag_path])[0].value
    data = do_stuff_with_the_array()
    return data
1 Like

Ya, the empty list seems to work