Hello all,
I am trying to get a Python script to work using a database variable. We are using NiceLabel 6, I tried executing the same script with NiceLabel 2017 and it does work; however, when trying to execute the same script with NiceLabel 6, I'm unable to do so.
I have attached screenshots of my script. Please let me know if there's anything else you need from me.
I followed the instructions on how to install Python to be used with NiceLabel 6 as well https://www.nicelabel.com/support/knowl ... ing-python
Thank you!
Python script using database variables.
Moderators: Georges, milos, NiceLabel Support Team
-
- Newcomer
- Posts: 4
- Joined: Mon Mar 28, 2016 9:41 pm
Python script using database variables.
- Attachments
-
- NiceLabel 2017.png (149.69 KiB) Viewed 8779 times
-
- NiceLabel6-label_large.png (196.82 KiB) Viewed 8780 times
Re: Python script using database variables.
When using variables in Python, you have to refer to their name as variable_name.Value.
If the variable_name itself contains dots in its name, your Python syntax will not be correct.
Python does not know how to handle the following.:
NiceLabel will always construct database variables out of two components: table name <dot> field name. You cannot really get rid of the dot in the middle or replace it with some other character.
There is, however, another workaround.
You could use a Concatenate function, configure one "database variable" as input and use the custom name of the output variable. Such Concatenate function will just be used to rename the variable.
You will have to create as many Concatenate functions as you have database variables that you intend to use inside Python script.
If the variable_name itself contains dots in its name, your Python syntax will not be correct.
Python does not know how to handle the following.:
Code: Select all
variable.name.Value

There is, however, another workaround.
You could use a Concatenate function, configure one "database variable" as input and use the custom name of the output variable. Such Concatenate function will just be used to rename the variable.
You will have to create as many Concatenate functions as you have database variables that you intend to use inside Python script.
Saso Fleiser
Senior Technical Product Specialist
Senior Technical Product Specialist
-
- Newcomer
- Posts: 4
- Joined: Mon Mar 28, 2016 9:41 pm
Re: Python script using database variables.
Thank you so much Saso! That is exactly what I needed to know.
Now the database variables work as expected in Python.



Now the database variables work as expected in Python.
Re: Python script using database variables.
My customer has 120 columns, most of them are required for printing.Saso wrote: ↑Mon Mar 26, 2018 8:55 amWhen using variables in Python, you have to refer to their name as variable_name.Value.
If the variable_name itself contains dots in its name, your Python syntax will not be correct.
Python does not know how to handle the following.:NiceLabel will always construct database variables out of two components: table name <dot> field name. You cannot really get rid of the dot in the middle or replace it with some other character.Code: Select all
variable.name.Value
![]()
There is, however, another workaround.
You could use a Concatenate function, configure one "database variable" as input and use the custom name of the output variable. Such Concatenate function will just be used to rename the variable.
You will have to create as many Concatenate functions as you have database variables that you intend to use inside Python script.
Does this mean, that I need create an additional function for EACH database field of the table if I want to use them in pyhton scripting?
Is there any improvement in NL 2019 to provide "Python Friendly" database field names?
Re: Python script using database variables.
Well, there is another (simpler) way, but it also requires some manual work.
You can update the "field alias" value for each field. NiceLabel will use "table_name.field_name" syntax. You can manually replace the period "." with some other character, such as underline "_".
Yes, you will have to do this 120 times.
Do the following:
You can update the "field alias" value for each field. NiceLabel will use "table_name.field_name" syntax. You can manually replace the period "." with some other character, such as underline "_".
Yes, you will have to do this 120 times.

Do the following:
- In Dynamic Data Manager, expand the connection to your database.
- Select each field to display its properties.
- Update the Field alias field. Replace period with some other character.
Saso Fleiser
Senior Technical Product Specialist
Senior Technical Product Specialist
Re: Python script using database variables.
Thank you, that is a much quicker solution, but it would be really an improvement to have some kind of automatic pyhton support.Saso wrote: ↑Mon Jan 07, 2019 12:17 pmWell, there is another (simpler) way, but it also requires some manual work.
You can update the "field alias" value for each field. NiceLabel will use "table_name.field_name" syntax. You can manually replace the period "." with some other character, such as underline "_".
Yes, you will have to do this 120 times.![]()