I haven't been able to find any bit of code that does this successfully. I need to delete some fields in a table that I'm modifying using a script I'm writing. I don't want the fields to be left on the table, but I'm pretty sure that I need the fields to calculate the centroids. I haven't found a way of calculating parcel centroids that works without adding a field to a table. I want the xCentroid and yCentroid fields to be calculated, and I want to delete those fields at the end of the script. Here the code I'm using.
try: # Set environment settings arcpy.env.workspace = "U:/JackBuildingFootprints.gdb" # Set local variables inFeatures = "parcelsCopy" xCentroid = "xCentroid" yCentroid = "yCentroid" fieldPrecision = 18 fieldScale = 11 # Add fields Remember to delete fields later. Get help with that arcpy.AddField_management(inFeatures, xCentroid, "DOUBLE", fieldPrecision, fieldScale) arcpy.AddField_management(inFeatures, yCentroid, "DOUBLE", fieldPrecision, fieldScale) # Calculate centroid arcpy.CalculateField_management(inFeatures, xCentroid, "!SHAPE.CENTROID.X!", "PYTHON_9.3") arcpy.CalculateField_management(inFeatures, yCentroid, "!SHAPE.CENTROID.Y!", "PYTHON_9.3") except Exception: e = sys.exc_info() print(e.args)