jostein

Str.format() function fails on Norwegian characters

Discussion created by jostein on Oct 24, 2013
Latest reply on Oct 25, 2013 by jostein
I have a script with a SearchCursor that runs through a feature layer and writes the feature properties to a semicolon divided text file. When it comes to a feature which has a property that contains one of the Norwegian letters æ, ø or å (html: æ, ø or å), the script crashes on the str.format() function

Traceback info:
  File "C:\Infrastructure_calculation.py", line 97, in <module>
    propStr += ";{0}".format(IS[index])

Error Info:
'ascii' codec can't encode character u'\xc6' in position 1: ordinal not in range(128)

ISs = da.SearchCursor("ISpoint_lyr", "*")
for IS in ISs:
    for index in range(len(ISs.fields)):
        if index <> shapeFieldIndex:
             propStr += ";{0}".format(IS[index])


I guess this have something to do with unicode encoding, but I have not been able to find a solution. Any input is appreciated!

Outcomes