import arcpy as a
a.env.overwriteOutput=1
a.env.workspace=r'F:\route\to\database\database.gbd'
a.management.MakeFeatureLayer('feature_class', 'feature_layer')
a.CalculateGeometryAttributes_management('feature_layer', ["new_field", "AREA_GEODESIC"], area_unit="SQUARE_KILOMETERS")
Tried to calculate it with both arcpy.management.CalculateGeometryAttribute and arcpy.CalculateGeometryAttributes_management as in https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-geometry-attributes.htm always led to:
KeyError: '#',
Failed to execute (CalculateGeometryAttributes),
geomValue = eval(geomCalcs[calcProp[1].upper()]).
I´m using PythonWin 3.7.11 and ArcGIS Pro 2.9.0
I read this thread, checked my code again, didn't help. https://community.esri.com/t5/python-questions/keyerror-when-calculating-geometry-in-arcpy/td-p/1030821