We have an 'import sys' statement at the beginning of an event handler script (for propertyChange -- on a property that changes a lot). This is on a "high traffic" screen that drives a lot of our actual manufacturing processes. Since joining this forum I've learned that it is bad practice to do imports on an event handler.
My question is, could I simply add import sys (or whatever other module is needed) in a client startup script? After which point I could call the related functions in any script contained in the project?
Side note, I have the same dumb question but for tags too. If we have a tag change script firing every so often that contains an import statement, where can we even move the import statement to? A gateway script?
You would refactor the event handler scripts to call functions from a project library script (or as many as needed to stay well-organized) instead. At the top of that project library script, you would put your import statements, no client startup script required.
The same thing would apply here. Put the actual logic in the project library script and then call it from your tag change script. If it's a gateway tag change script, which it probably should be, change script on the tag itself (thanks @JordanCClark), you'd set up your project as the gateway scripting project in the gateway Config section.
As a bonus, this should make it easier to update any repeated code as it would only exist in one place.