<?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: Str.format() function fails on Norwegian characters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231558#M17959</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mark the format string as unicode (with a u beforehand &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;u"like this"&lt;/SPAN&gt;&lt;SPAN&gt;) so it doesn't try to downcast your Norwegian characters to ascii.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ISs = da.SearchCursor("ISpoint_lyr", "*")
for IS in ISs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr = u""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for index in range(len(ISs.fields)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index &amp;lt;&amp;gt; shapeFieldIndex:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr += u";{0}".format(IS[index])
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:44:00 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2021-12-11T11:44:00Z</dc:date>
    <item>
      <title>Str.format() function fails on Norwegian characters</title>
      <link>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231557#M17958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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: &amp;amp;aelig;, &amp;amp;oslash; or &amp;amp;aring;), the script crashes on the str.format() function&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Infrastructure_calculation.py", line 97, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr += ";{0}".format(IS[index])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error Info:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'ascii' codec can't encode character u'\xc6' in position 1: ordinal not in range(128)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;ISs = da.SearchCursor("ISpoint_lyr", "*")
for IS in ISs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for index in range(len(ISs.fields)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index &amp;lt;&amp;gt; shapeFieldIndex:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr += ";{0}".format(IS[index])&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess this have something to do with unicode encoding, but I have not been able to find a solution. Any input is appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Oct 2013 10:19:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231557#M17958</guid>
      <dc:creator>JosteinSvegården</dc:creator>
      <dc:date>2013-10-24T10:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Str.format() function fails on Norwegian characters</title>
      <link>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231558#M17959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mark the format string as unicode (with a u beforehand &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;u"like this"&lt;/SPAN&gt;&lt;SPAN&gt;) so it doesn't try to downcast your Norwegian characters to ascii.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ISs = da.SearchCursor("ISpoint_lyr", "*")
for IS in ISs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr = u""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for index in range(len(ISs.fields)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index &amp;lt;&amp;gt; shapeFieldIndex:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; propStr += u";{0}".format(IS[index])
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:44:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231558#M17959</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T11:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Str.format() function fails on Norwegian characters</title>
      <link>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231559#M17960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Jason, that did it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is easy to get lost in all this encoding stuff. So for readers that might bump into this thread later, I will add that to be able to write the resulting string to a file, I had to convert the unicode string to a string of bytes using the string.encode() function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;STR_result = STR_result.encode('utf8', 'replace')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See &lt;/SPAN&gt;&lt;A href="http://pythonhosted.org/kitchen/unicode-frustrations.html"&gt;http://pythonhosted.org/kitchen/unicode-frustrations.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Oct 2013 07:05:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/str-format-function-fails-on-norwegian-characters/m-p/231559#M17960</guid>
      <dc:creator>JosteinSvegården</dc:creator>
      <dc:date>2013-10-25T07:05:31Z</dc:date>
    </item>
  </channel>
</rss>

