I have a feature class whose attribute table looks like this:

Latitude | Longitude | Area

For the area column, all rows are null. I would like to put in a specific value for all rows using Python.

I know how to do this on the front-end in the ArcMaps application ( right click > Open Attribute Table > right click on column > field calculator > input value).

How can I accomplish this programmatically using Python?

  • Do you want to calculate the area for each feature? – Alex Tereshenkov Jun 11 '14 at 18:49

The simplest way, until you are more familiar with the syntax, would be to use the field calculator as you normally do and then go to Geoprocessing -> Results. From there, you can expand Current Session and, right-clicking on the most recent tool that was run, select Copy as Python Snippet.

You'll likely have to change the names of a few inputs, but that should get you started.


You can calculate the values for a column with Python by using either a GP tool Calculate Field or arcpy UpdateCursor (this one is faster when working with large datasets).

For calculating the geometrical properties of features, you can either use GP tool Add Geometry Attributes or using tokens (such as SHAPE@AREA) of update cursor.

  • 1
    +1 for cursors, specifically the data access module. I don't really use Calculate Field anymore. – Paul Jun 11 '14 at 18:55
  • 1
    @Paul, I still do :) sometimes it is just plain easier syntax wise. Of course only for minor datasets. – Alex Tereshenkov Jun 11 '14 at 18:58
  • Anything past one or two lines, yes. :) – Paul Jun 11 '14 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.