Python Module Level Variables vs. Client Tags

I just wrote this blog post that is about the benefits of using Python module level variables over client tags in Ignition clients for storing and using global data: nickmudge.info/post/python-modul … lient-tags

I’m curious what people think on this topic.

If I have a Client Tag, I can bind directly to that Client Tag. How would you bind a property to your Python variable?

Hi Pat,

It is a good question. I would add a propertyChange script to the component that has the property. When the property changes the propertyChange script sets the Python module variable to the new value.

I would have a function defined in the Python module for setting the Python variable. The function would update the component property when the variable value changes.

As a note: I am working on a new “runFunction” expression function that enables the use of expression bindings to bind data from Python variables to component properties and other places, and will re-executed when the Python variable value changes.

Another note: Python module level variables are most useful when working with aggregate data types (working with a variable amount of data). Client tags have useful scalar data types like Integer, Float, String and so are most useful for holding single value data.

I admit that a bidirection binding between a client tag and a component property is really easy, but I don’t know if I would do it because I’m usually doing something else in the window. For example if there is a visionWindowOpen event script with some code to setup the window, it makes sense to set property values there.

As Pat points out, the value of a module level variable cannot be pushed out automatically to anything using it - you’ll have to do this manually. This means it’s only useful for client-specific back-end stores of structured data - a fairly small use case I would have thought.

It’s also worth pointing out that you have to put this code into the ‘project’ script library. If you put it into the ‘shared’ script library it will work in the Designer but fail in a view Client.