Issue Returning Unicode in Python Function

Discussion created by BrokenLegMike on Jan 31, 2013
Latest reply on Feb 1, 2013 by cfox-esristaff
Hey everyone,

I'm trying to encode some unicode in a label expression using the python parser and defining a function. I'm geting a weird unicode value being returned and I can't figure out why.

In the following code:

def FindLabel ([Unicode_Value]):
  import locale
  deflang, defencoding = locale.getdefaultlocale()
  S = u'Libert{}'.format(u'[Unicode_Value]'.encode(defencoding))
  return S

Where the field [Unicode_Value] contains records that have unicoding strings for each record. In my case, they are all u'\u00e9' which is the code for é

Instead, it returns 'Libertesri__0'

This should return 'Liberté' as the encoding on my computer is set to 'cp1252' the US Standard. I can get this to work if I hard code the é unicode value into the function like this:

S = u'Libert{}'.format(u'\u00e9'.encode(defencoding))

but somehow I think the file geodatabase feature class attribute table is throwing some ESRI unicoding when I use the field in my function.

can anyone suggest how I can fix this?