global variables in python

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Valued Contributor
Posts: 26
Joined: Fri Jul 20, 2018 6:09 pm

global variables in python

Post by sdwarwick » Thu Aug 02, 2018 4:55 pm

I run into situations where I want to read data in one script and make it available in another one. The data is typically either a python dict object or some complex dotnet object. Since Nicelabel variables are only text, you can't use them to store these kinds of objects. further, the way Ironpython is implemented in nicelabel, "global" objects are restricted to the script you're running, and don't persist to other scripts.

Fortunately, the "sys" object DOES persist across all scripts and is writable.

So the tip is, when you need to persist an object, just add it to the sys object:

generate value in one script:

Code: Select all

import sys

sys.global_holder = complex_object

use value in another:

Code: Select all

import sys

complex_object = sys.global_holder

using this process, I can query external resources for XML/JSON data and use it to populate fields on multiple labels

Posts: 1
Joined: Mon Dec 03, 2018 12:01 pm

Re: global variables in python

Post by allenvarna » Mon Dec 03, 2018 12:03 pm

Post Reply