<?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: arcpy: problem with coding in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248971#M4242</link>
    <description>&lt;P&gt;Thanks for your reaction, but with Python 2 the script keeps crashing. As our organization is in the transition to ArcGIS Pro I ran my original script with Python 3 as well and now it worked!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jan 2023 07:24:21 GMT</pubDate>
    <dc:creator>GIS_Limburg_Province_Belgium</dc:creator>
    <dc:date>2023-01-18T07:24:21Z</dc:date>
    <item>
      <title>arcpy: problem with coding</title>
      <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248412#M4236</link>
      <description>&lt;P&gt;With arcpy I made a script to get the properties of the featureclasses and tables in Esri geodatabases (.gdb), and the properties of its fields. Simple script and it always has run well.&lt;BR /&gt;But now a fieldname happens to have the character € in it (fieldname = 'Budget_€') and the script crashes with the message 'UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 59: ordinal not in range(128)'.&lt;BR /&gt;Yes, a coding issue, and it shouldn't be that difficult to solve. But all I tried fails with the same message.&lt;/P&gt;&lt;P&gt;What I tried and crashes:&lt;/P&gt;&lt;P&gt;# -*- coding: utf-8 -*- (also tried # -*- coding: cp1252 -*-)&lt;BR /&gt;import codecs&lt;/P&gt;&lt;P&gt;&amp;lt; code &amp;gt;&lt;/P&gt;&lt;P&gt;for field in fieldLst:&lt;BR /&gt;f.write(gdbbasefolder+"\t"+gdbname+"\t"+table+"\t"+ field.name+"\t"+ field.type+"\t"+ str(field.length)+"\t"+shapeType +"\t"+str(factoryCode) +"\t"+hasZ +"\t"+hasM +"\t"+ hasSpatialIndex+"\t"+ str(recs))&lt;/P&gt;&lt;P&gt;in which 'field.name' gives the problems.&lt;/P&gt;&lt;P&gt;I also tried:&lt;/P&gt;&lt;P&gt;field.name.encode('utf-8')&lt;/P&gt;&lt;P&gt;field.name.decode('utf-8')&lt;/P&gt;&lt;P&gt;but it keeps crashing.&lt;/P&gt;&lt;P&gt;Using Python 2.7.14, running in IDLE 2.7.14.&lt;/P&gt;&lt;P&gt;Read several threads about this, but nothing helps.&lt;/P&gt;&lt;P&gt;What should I do?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 07:15:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248412#M4236</guid>
      <dc:creator>GIS_Limburg_Province_Belgium</dc:creator>
      <dc:date>2023-01-16T07:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy: problem with coding</title>
      <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248458#M4237</link>
      <description>&lt;P&gt;Don't know if it helps, but I tried to print the € in a field name like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

featureclass = r"YourPath2FC"
field_names = [f.name.encode("windows-1252") for f in arcpy.ListFields(featureclass)]

print (field_names)

for f in field_names:
    print f.decode("windows-1252")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 13:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248458#M4237</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2023-01-16T13:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy: problem with coding</title>
      <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248512#M4238</link>
      <description>&lt;P&gt;This isn't an issue with ArcGIS Pro, so maybe it is time to switch?&amp;nbsp; Seriously though, the clock is ticking on ArcMap, and the clock long stopped for Python 2.&lt;/P&gt;&lt;P&gt;For Python 2 (&lt;EM&gt;I would not recommend for Python 3)&lt;/EM&gt;, you could consider changing the default standard output to UTF-8 at the start of your script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sys
import codecs
sys.stdout = codecs.getwriter("utf8")(sys.stdout)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Prior to Python 3.6, Python used the ANSI APIs to interact with the Windows OS, which usually meant cp437 for English and many other locales.&amp;nbsp; As you discovered, the euro symbol is not part of cp437, hence the error when trying to print or write from Python 2.7.14.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jan 2023 17:46:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248512#M4238</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-16T17:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy: problem with coding</title>
      <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248971#M4242</link>
      <description>&lt;P&gt;Thanks for your reaction, but with Python 2 the script keeps crashing. As our organization is in the transition to ArcGIS Pro I ran my original script with Python 3 as well and now it worked!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 07:24:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248971#M4242</guid>
      <dc:creator>GIS_Limburg_Province_Belgium</dc:creator>
      <dc:date>2023-01-18T07:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy: problem with coding</title>
      <link>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248972#M4243</link>
      <description>&lt;P&gt;Thanks. You are right: switch to Pro, and we are already in transition. My original script runs anyway in Python 3.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 07:27:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/arcpy-problem-with-coding/m-p/1248972#M4243</guid>
      <dc:creator>GIS_Limburg_Province_Belgium</dc:creator>
      <dc:date>2023-01-18T07:27:19Z</dc:date>
    </item>
  </channel>
</rss>

