Problem with string lists


i have a problem with lists of string:

This behavior is somewhat strange… I want the letter “ì” to appear accented in the list and that’s it without any strange characters.

How can I do?


Try this:

a = [u"Lunedì"]

Though you shouldn’t really fret about the “toString” representation of a list - you have no control over that.

Already tried … But unfortunately without success:

Well, tough luck, the string representation of a list is out of your control :man_shrugging:

Try assembling your own string representation?

I use a list of strings as a path of variables in which I have to write a value … The path must be correct and not with strange hexadecimal symbologies:


Why Ignition interprets a string in a list like this when Python normally does it correctly:

How do you mean?

If you print every item in the list, you get the output you expect.

Also, import unicode_literals from __future__ to free yourself of prepending all your string with u.

from __future__ import unicode_literals

a = "Lunedì"

print a, type(a)

a = ["Lunedì"]

for item in a:
    print item, type(item)


Lunedì <type 'unicode'>
Lunedì <type 'unicode'>


The actual value of the string is unchanged. The string representation you get from print() is not, but it should not matter to your code, and if it does, you’re doing something wrong.


This is why these hexadecimal characters are not good…

Can you share your actual code? Unless you’re parsing the string representation of a list back into a list somehow, you probably have a different problem.

This is the custom method called “getTimer(id)” triggered by the valueChanged of dropdown list:

	paths = ["Week_Day_%s", "On_Minute_%s", "On_Hour_%s"]
	tags = []
	for path in paths:
		tags.append("[default]" + path % id)
	timer, minute, hour = system.tag.readBlocking(tags, 5000)
	timer = timer.value
	minute = minute.value
	hour = hour.value
	paths = ["Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato", "Domenica"]
	tags = []
	for path in paths:
		tags.append("[default]Timers/" + path)
	vals = []
	vals.append(utils.getBit(0, timer))		# Domenica
	vals.append(utils.getBit(1, timer))		# Lunedì
	vals.append(utils.getBit(2, timer))		# Martedì
	vals.append(utils.getBit(3, timer))		# Mercoledì
	vals.append(utils.getBit(4, timer))		# Giovedì
	vals.append(utils.getBit(5, timer))		# Venerdì
	vals.append(utils.getBit(6, timer))		# Sabato
	system.tag.writeBlocking(tags, vals, 5000)

Try adding the following import statement at the very top

from __future__ import unicode_literals

Yes, thanks. It works (only from project script)!

The only thing is that I can’t use this import with the custom method but only from a project script:


You get the same error with those string literals marked as unicode, with the u prefix flag?

It’s a Python 2 limitation/behavior to parse unflagged string literals as ISO-8859. You can either put your logic in a project library script (in which case you should be able to use the from __future__ line @thecesrom suggested) or you must tag your string literals as Unicode to ensure they’re parsed correctly.

1 Like

As you said, it works either with the from __future__ import unicode_literals method, or with [u"Lunedì", ...] and also with this one that i chose:


	tags = []
	for path in paths:
		tags.append("[default]Timers/" + unicode(path, "utf-8"))


Thanks everyone for the tip! :slight_smile:

1 Like