Is there a way to handle label variable names containing a period (".") when referencing them in Python functions?

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
dan2
Newcomer
Posts: 3
Joined: Sat Aug 03, 2019 4:30 am

Is there a way to handle label variable names containing a period (".") when referencing them in Python functions?

Post by dan2 » Tue Nov 26, 2019 6:25 pm

Since Nicelabel allows variable names to contain a period while Python does not, is there a way to handle this when referencing the variable in a Python script?

At the moment, if you use the "Insert Data Source" button in the Script Editor, it simply adds the above variable as would any other variable without a period:

Inserting a variable with the name Amazon.UPC results in the following being added to the Python script:

Code: Select all

Amazon.UPC.Value
Python will interpret the Amazon.UPC part of this statment first and thinks you are attempting to call the a method called UPC from a class/module named Amazon which does not exist and so it throws the following error:

Code: Select all

System error:

name "Amazon" is not defined.
Is there a way to somehow escape the Python interpreter similar to how you add data sources into the SQL script edior using the syntax :Amazon.UPC?

If not, may I suggest adding this stipulation to the Python KB article and/or the Niceforms programming guide?

https://www.nicelabel.com/support/knowl ... web--cloud

User avatar
Mytch
NiceLabel Support
NiceLabel Support
Posts: 103
Joined: Fri Jul 13, 2018 10:26 pm
Location: Milwaukee, Wisconsin
Contact:

Re: Is there a way to handle label variable names containing a period (".") when referencing them in Python functions?

Post by Mytch » Tue Nov 26, 2019 8:32 pm

dan2,

Simply rename the variable in NiceLabel to something else not containing a period. If you create a troublesome variable name in NiceLabel, you already receive the warning below:
screenshot_12.jpg
screenshot_12.jpg (21.74 KiB) Viewed 47 times
Of course, we allow almost any variable name in NiceLabel, because the applications have no real restrictions with naming. But when used with other scripting languages, you must respect the syntax of the language. The User Guide even states, "NOTE: Avoid using non-alphanumerical characters when defining the variable name".

In this case, there is nothing really to do here besides rename the variable to accommodate your Python script.

Regards,
Mytch

Post Reply