Managing UTF-8 encoded fields in field calculation

2716
2
Jump to solution
06-16-2016 01:17 PM
PatricePineault1
New Contributor III

Hello,

I am trying to write a Python code block in a Field Calculation but I have problems with fields containing "é" "è", etc.

--------------------------------------------------------

ERROR 000539: Error running expression: legend_field(u"Laferrière")

Traceback (most recent call last):

  File "<expression>", line 1, in <module>

  File "<string>", line 5, in legend_field

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 7: ordinal not in range(128)

--------------------------------------------------------

Here is the code so far in the code block:

# -*- coding: utf-8 -*-

prop_list = []

def legend_field(prop):

  if (str(prop) not in prop_list):

    prop_list.append(str(prop))

  return "sds"

0 Kudos
1 Solution

Accepted Solutions
PatricePineault1
New Contributor III

I solved my problem by removing the str() that was wrapping prop in line 6

View solution in original post

0 Kudos
2 Replies
PatricePineault1
New Contributor III

I also tried to .encode('utf-8') the string I am trying to append

0 Kudos
PatricePineault1
New Contributor III

I solved my problem by removing the str() that was wrapping prop in line 6

0 Kudos