Import Script vs Calling a Function Inline

I’m trying to figure out exactly what happens when I first import a script in my code compared to when I just call the function without explicitly importing the script. For example, if I had a script called “Test” with a function inside it called fTest(), what is the difference between these two examples?

import Test

My specific situation is that I have been using the second example, but I think it is causing me a specific problem. The function that I am calling relies on data from a query that runs at the top of the “Test” script and creates a variable with a Python Dataset. It appears the variable was somehow being cached and did not refresh every time I called the function. I am wondering if importing the script will update the variable every time.

There’s no practical difference, and what you are seeing is expected behavior for script modules in python and jython. Script modules execute at the top level just once when imported (until a project save triggers a “script reload”). In Ignition, calling out an element from a script module implicitly imports it. If you need something to execute every time a function is called, put that code in the function.

1 Like

Thanks! I have made the change so that the queries are run every time the function executes.