<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issue Returning Unicode in Python Function in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412274#M32462</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No, I didn't get that to work. I have been playing around with this can you use the utf-8 representation of the character:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"\xc3\xa9"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I use that in a field this label expression works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def FindLabel ([Unicode_Value]):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; S = u'Libert{}'.format(unicode([Unicode_Value],"utf8"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return S&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Feb 2013 16:33:52 GMT</pubDate>
    <dc:creator>ChrisFox3</dc:creator>
    <dc:date>2013-02-01T16:33:52Z</dc:date>
    <item>
      <title>Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412269#M32457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel ([Unicode_Value]):
&amp;nbsp; import locale
&amp;nbsp; deflang, defencoding = locale.getdefaultlocale()
&amp;nbsp; S = u'Libert{}'.format(u'[Unicode_Value]'.encode(defencoding))
&amp;nbsp; return S&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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 é&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead, it returns 'Libertesri__0'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;S = u'Libert{}'.format(u'\u00e9'.encode(defencoding))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; but somehow I think the file geodatabase feature class attribute table is throwing some ESRI unicoding when I use the field in my function. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;can anyone suggest how I can fix this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jan 2013 21:38:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412269#M32457</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2013-01-31T21:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412270#M32458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This issue is you are placing the variable [STATE_NAME] inside single quotes, you will see the value esri__0 is returned if you did the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ([Unicode_Value]):
&amp;nbsp; return '[Unicode_Value]'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412270#M32458</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2021-12-11T18:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412271#M32459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This issue is you are placing the variable [STATE_NAME] inside single quotes, you will see the value esri__0 is returned if you did the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ([Unicode_Value]):
&amp;nbsp; return '[Unicode_Value]'
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hmmm...by [STATE_NAME] you meant my field of [Unicode_Value]?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And you're right, by using &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;return '[Unicode_Value]'&lt;/PRE&gt;&lt;SPAN&gt; I do get esri__0 returning. That's not what I want. I want the é to return....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:42:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412271#M32459</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-11T18:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412272#M32460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Right, sorry that was the field name i was playing with on my side. Yea because you are surronding a variable name with quotes it is returning the string representation of the variable name (esri__0) rather than the string value ('\u00e9') referenced by the variable. The reason you see esri__0 is because we actually modify the function to replace the [fieldname] with esri__0 before the function is run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So does this not work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ([Unicode_Value]):
&amp;nbsp; import locale
&amp;nbsp; deflang, defencoding = locale.getdefaultlocale()
&amp;nbsp; S = u'Libert{}'.format([Unicode_Value].encode(defencoding))
&amp;nbsp; return S&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412272#M32460</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2021-12-11T18:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412273#M32461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Chris, thanks for the explanation about why I am getting esri__0. That totally makes sense. I think I was thinking too hard when I added in the quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried your modified script and I am getting &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;Libert'\u00e9'&lt;/PRE&gt;&lt;SPAN&gt; returned. It doesn't seem to be encoding the values in my field. I've tried to modify the string in my field to the following &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;'\u00e9'&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;\u00e9&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;u'\u00e9'&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;None of which returns the coded value, just the string literal after 'Libert'. Is this working on your end? Do you actually get &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;Liberté&lt;/PRE&gt;&lt;SPAN&gt; returning?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for taking your time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Feb 2013 14:22:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412273#M32461</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2013-02-01T14:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Returning Unicode in Python Function</title>
      <link>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412274#M32462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No, I didn't get that to work. I have been playing around with this can you use the utf-8 representation of the character:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"\xc3\xa9"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I use that in a field this label expression works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def FindLabel ([Unicode_Value]):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; S = u'Libert{}'.format(unicode([Unicode_Value],"utf8"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return S&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Feb 2013 16:33:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-returning-unicode-in-python-function/m-p/412274#M32462</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2013-02-01T16:33:52Z</dc:date>
    </item>
  </channel>
</rss>

