<?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: KeyError: '#' When Calculating Geometry in Arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1033588#M60241</link>
    <description>&lt;P&gt;That worked! I *knew* it was something that was staring me in the face. Thank you, all!&lt;/P&gt;</description>
    <pubDate>Fri, 05 Mar 2021 20:13:32 GMT</pubDate>
    <dc:creator>JamesWilcox1970</dc:creator>
    <dc:date>2021-03-05T20:13:32Z</dc:date>
    <item>
      <title>KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030821#M60133</link>
      <description>&lt;P&gt;As part of a larger script, I have code that checks to see if a particular field exists. If not, it creates it and calculate its area. The script works just fine until it goes to calculate the area of the newly created field, where it gives me KeyError: '#'. Is this error because the field was just created? If so, how do I work around it?&lt;/P&gt;&lt;P&gt;I am running Python 3.6 with PyCharm.&lt;/P&gt;&lt;P&gt;Here is the code I am having issues with--"projArea" is the project area feature class.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Test to see if there is an "Acres" field in the Project Area FC.
projFields = arcpy.ListFields(projArea)  # List of fields in project area fc
x = False  # Default condition is that the field doesn't exist
for f in projFields:
    if f.name == "Acres":  # If there is a field named "Acres"
        x = True
if x is not True:  # If none of the fields are named "Acres"
    arcpy.AddMessage("{} does not have an Acres field. Creating field.".format(projArea))
    arcpy.AddField_management(projArea, 'Acres', 'DOUBLE')  # Create the field
    arcpy.AddMessage("Calculating area.")
    arcpy.management.CalculateGeometryAttributes(projArea, 'Acres', area_unit="ACRES")  # Calculate the area
    arcpy.AddMessage("Area calculated.")&lt;/LI-CODE&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 23:23:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030821#M60133</guid>
      <dc:creator>JamesWilcox1970</dc:creator>
      <dc:date>2021-02-25T23:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030829#M60134</link>
      <description>&lt;P&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"Left"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN class="hljs-string"&gt;"EXTENT_MIN_X"&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;in your case&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;[projArea, 'AREA']&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-geometry-attributes.htm" target="_blank"&gt;Calculate Geometry Attributes (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;a list is required for the first parameter, the field name and the property&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 23:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030829#M60134</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-25T23:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030889#M60137</link>
      <description>&lt;P&gt;Replace&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateGeometryAttributes(projArea, 'Acres', area_unit="ACRES")&lt;/LI-CODE&gt;&lt;P&gt;With arcpy.management.CalculateGeometryAttributes(projArea, [["Acres", "AREA"]], area_unit ="ACRES")&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 05:28:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1030889#M60137</guid>
      <dc:creator>DavinWalker2</dc:creator>
      <dc:date>2021-02-26T05:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1031804#M60176</link>
      <description>&lt;P&gt;What Dan and Davin said.&lt;/P&gt;&lt;P&gt;Plus, you can just do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#projFields = arcpy.ListFields(projArea)
#x = False
#for f in projFields:
#    if f.name == "Acres":
#        x = True

projFieldNames = [f.name for f in arcpy.ListFields(projArea)]  # extract field names
x = "Acres" in projFieldNames  # Test if field "Acres exists&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 06:58:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1031804#M60176</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-03-02T06:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1033588#M60241</link>
      <description>&lt;P&gt;That worked! I *knew* it was something that was staring me in the face. Thank you, all!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 20:13:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1033588#M60241</guid>
      <dc:creator>JamesWilcox1970</dc:creator>
      <dc:date>2021-03-05T20:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: KeyError: '#' When Calculating Geometry in Arcpy</title>
      <link>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1681096#M75083</link>
      <description>&lt;P&gt;Encountered this issue too. The trick ended up being that I had to pay attention to the Data Type for the geometry_type parameter in the function arcpy.CalculateGeometryAttributes(). Documentation says it is a Value Table type, which was new to me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/3.4/tool-reference/data-management/calculate-geometry-attributes.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/3.4/tool-reference/data-management/calculate-geometry-attributes.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="geometry_property parameter data type" style="width: 951px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/147536i06631B30393B0A3D/image-size/large?v=v2&amp;amp;px=999" role="button" title="valuelistscreenshot.png" alt="geometry_property parameter data type" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;geometry_property parameter data type&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Value Table documentation&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/3.4/arcpy/classes/valuetable.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/3.4/arcpy/classes/valuetable.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solution using the list of lists appears to be satisfying the Value Table format.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;value_table = arcpy.ValueTable(2) # 2 is the number of columns I needed
value_table.addRow(["field name 1", "data type 1"]) # 0 index
value_table.addRow(["field name 2", "data type 2"]) # 1 index
# NOTE: see https://pro.arcgis.com/en/pro-app/3.4/arcpy/geoprocessing_and_python/defining-parameter-data-types-in-a-python-toolbox.htm for options on data types

arcpy.management.CalculateGeometryAttributes(in_features=feature_layer_name, geometry_property=value_table.getRow(0), coordinate_system=sr, coordinate_format="Same as input")
# NOTE: sr is an arcpy.SpatialReference() object&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you call value_table.exportToString() on my example table above you get the following string format. Maybe the list of lists and the below quoted space separated and semi-colon delimited string also does the trick (?)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;"'field name 1' 'data type 1';'field name 2' 'data type 2'"&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jan 2026 15:56:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/m-p/1681096#M75083</guid>
      <dc:creator>ConradSchaefer__DOIT_</dc:creator>
      <dc:date>2026-01-30T15:56:49Z</dc:date>
    </item>
  </channel>
</rss>

