<?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: Python non-ascii characters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-non-ascii-characters/m-p/113247#M8846</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This should remove the non-asciis:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def removeNonAscii(s): return "".join(filter(lambda x: ord(x)&amp;lt;128, s)) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, something like this in your code should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;InsertValue = removeNonAscii(str(row.GetValue(CurrentField['Name'])))&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, 25 May 2012 17:57:36 GMT</pubDate>
    <dc:creator>MikeWynne</dc:creator>
    <dc:date>2012-05-25T17:57:36Z</dc:date>
    <item>
      <title>Python non-ascii characters</title>
      <link>https://community.esri.com/t5/python-questions/python-non-ascii-characters/m-p/113246#M8845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python file that creates and populates a table in ms sql (via modelbuilder).&amp;nbsp; The only sticking point is that the code breaks if there are any non-ascii characters or single apostrophes (and there are quite a few of each).&amp;nbsp; Although I can run the replace function to rid the strings of apostrophes, I would prefer to keep it intact. I have also tried converting the data into utf-8, but no luck there either.&amp;nbsp; The python code is attached as a text file.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An example of the error messages are "'ascii' codec can't encode character u'\2013' in position..." (for non-ascii characters) and "class 'pyodbc.ProgrammingError'&amp;gt;: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server] Incorrect syntax near 'S, 230 X 90M.; Eligibilty..." (for the single quotes). The python code is included below. I believe the point in the code where this break occurs is after the following line: InsertValue = str(row.GetValue(CurrentField['Name'])).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;James&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Sep 2011 17:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-non-ascii-characters/m-p/113246#M8845</guid>
      <dc:creator>JamesDewar</dc:creator>
      <dc:date>2011-09-28T17:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python non-ascii characters</title>
      <link>https://community.esri.com/t5/python-questions/python-non-ascii-characters/m-p/113247#M8846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This should remove the non-asciis:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def removeNonAscii(s): return "".join(filter(lambda x: ord(x)&amp;lt;128, s)) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, something like this in your code should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;InsertValue = removeNonAscii(str(row.GetValue(CurrentField['Name'])))&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, 25 May 2012 17:57:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-non-ascii-characters/m-p/113247#M8846</guid>
      <dc:creator>MikeWynne</dc:creator>
      <dc:date>2012-05-25T17:57:36Z</dc:date>
    </item>
  </channel>
</rss>

