<?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 Dealing with accents on inputs for text files in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166358#M12822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am currently creating a textfile in which I would like to write the users input. it needs to be able to deal with characters that contain accents i.e."é". The file needs to be coded on utf-8 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have managed to copy into the text file using utf-8 coding by by using codecs. However, I am having a hard time figuring out how to do this given a users input?.. so far&amp;nbsp; i have something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import codecs import sys&amp;nbsp;&amp;nbsp; aninput = sys.argv[1]&amp;nbsp;&amp;nbsp;&amp;nbsp; textfile =&amp;nbsp; codecs.open("testfile","wt","utf-8") textfile.write(u"é") # this works&amp;nbsp; textfile.write(aninput) # this fails assuming that aninput = "é" textfile.close()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jul 2012 00:19:20 GMT</pubDate>
    <dc:creator>ZulyG</dc:creator>
    <dc:date>2012-07-26T00:19:20Z</dc:date>
    <item>
      <title>Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166358#M12822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am currently creating a textfile in which I would like to write the users input. it needs to be able to deal with characters that contain accents i.e."é". The file needs to be coded on utf-8 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have managed to copy into the text file using utf-8 coding by by using codecs. However, I am having a hard time figuring out how to do this given a users input?.. so far&amp;nbsp; i have something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import codecs import sys&amp;nbsp;&amp;nbsp; aninput = sys.argv[1]&amp;nbsp;&amp;nbsp;&amp;nbsp; textfile =&amp;nbsp; codecs.open("testfile","wt","utf-8") textfile.write(u"é") # this works&amp;nbsp; textfile.write(aninput) # this fails assuming that aninput = "é" textfile.close()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 00:19:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166358#M12822</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2012-07-26T00:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166359#M12823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, Zuly,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try changing the line where you set aninput to this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;aninput = sys.argv[1].decode(sys.getfilesystemencoding())&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 12:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166359#M12823</guid>
      <dc:creator>AlanRussian</dc:creator>
      <dc:date>2012-07-26T12:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166360#M12824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Alan, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I continue to get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.UnicodeEncodeError'&amp;gt;: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 15:36:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166360#M12824</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2012-07-26T15:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166361#M12825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Alan, &lt;BR /&gt;I continue to get the following error:&lt;BR /&gt;&lt;BR /&gt;&amp;lt;type 'exceptions.UnicodeEncodeError'&amp;gt;: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)&lt;BR /&gt;Failed to execute (Script).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does the following script not work for you?&amp;nbsp; It works fine for me, and if I remove the decode, I get the same error as you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import codecs
import sys


aninput = sys.argv[1].decode(sys.getfilesystemencoding())


textfile =&amp;nbsp; codecs.open("testfile","w","utf-8")
textfile.write(aninput)
textfile.close()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:40:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166361#M12825</guid>
      <dc:creator>AlanRussian</dc:creator>
      <dc:date>2021-12-11T08:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166362#M12826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Does the following script not work for you?&amp;nbsp; It works fine for me, and if I remove the decode, I get the same error as you.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import codecs
import sys


aninput = sys.argv[1].decode(sys.getfilesystemencoding())


textfile =&amp;nbsp; codecs.open("testfile","w","utf-8")
textfile.write(aninput)
textfile.close()
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Got it to work! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; THANXS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the reason it would'nt work was because I was adding the following line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"arcpy.AddMessage(str(aninput))"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:40:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166362#M12826</guid>
      <dc:creator>ZulyG</dc:creator>
      <dc:date>2021-12-11T08:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with accents on inputs for text files</title>
      <link>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166363#M12827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Got it to work! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; THANXS&lt;BR /&gt;the reason it would'nt work was because I was adding the following line:&lt;BR /&gt;"arcpy.AddMessage(str(aninput))"&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fantastic!&amp;nbsp; Glad to hear.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 18:08:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/dealing-with-accents-on-inputs-for-text-files/m-p/166363#M12827</guid>
      <dc:creator>AlanRussian</dc:creator>
      <dc:date>2012-07-26T18:08:14Z</dc:date>
    </item>
  </channel>
</rss>

