Problem: Cyrillic alphabet in array

I have some problem with Cyrillic alphabet in ignition scripting. When i get username from database that contains a Cyrillic character it’s ok as long as I keep it in single variable. But once i asign it into array, it changes it into some wired characters. For example code is:
name1 = “Ничепоренко В.”
name2 = “Домосканов Д.”
array = [name1, str(name2)]
print name1, name2
print array

And the result:
Ничепоренко В. Домосканов Д.
[’\xd0\x9d\xd0\xb8\xd1\x87\xd0\xb5\xd0\xbf\xd0\xbe\xd1\x80\xd0\xb5\xd0\xbd\xd0\xba\xd0\xbe \xd0\x92.’, ‘\xd0\x94\xd0\xbe\xd0\xbc\xd0\xbe\xd1\x81\xd0\xba\xd0\xb0\xd0\xbd\xd0\xbe\xd0\xb2 \xd0\x94.’]

Is there any way to keep strings in array that are not converted to unicode?

This seems to be a quirk of the Jython list string representation. The values are what you would expect:

print array[0]
print array[1]

would yield

Ничепоренко В.
Домосканов Д.
1 Like

Note that you can print them all in one go, by using a join.

However, when trying in the console with Cyrillic, I just got a bunch of question marks. Most likely because the used font doesn’t have Cyrillic glyphs (and that’s probably why printing an array reverts to printing the utf representation). However, printing simple accents did work.

name1 = u"Tést"
name2 = u"Héló"
array = [name1, str(name2)]

print ",".join(array)
1 Like

OK, so it does work with print but when using SQL database I have the same error. So the solution is to decode string:
name1 = name1.decode(‘utf8’)
And it helped :slight_smile:

P.s. also the column in database have to be in proper encoding. For me it was cp1251_general.

1 Like