Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a Python script with ArcGIS 10 to count the number of unique string values in a feature class. My script works if there are values in the field but if there are any NUll values in the field it crashes. Any Ideas?

My code is below:

import arcpy
import operator

inTable = arcpy.GetParameterAsText(0)
stringField = arcpy.GetParameterAsText(1)

stringList = [row.getValue(stringField) for row in arcpy.SearchCursor
                                       (inTable, "", "",stringField)]
share|improve this question
Try using the SearchCursor command with no parameters besides inTable: stringList = [row.getValue(stringField) for row in arcpy.SearchCursor(inTable)] – dmahr Feb 2 '12 at 14:49
Does the script fail during the loop through the SearchCursor or does it fail later on? It seems that the list comprehension should be able to handle collecting None values, which is the Python representation of NULL. – Brian Feb 27 '12 at 14:24

Null values are equal to the python None so you could also handle null values like this

if row.getValue(stringField) == None:
    do something
if row.getValue(stringField) != None:
    do something else
share|improve this answer

Use isNull(field_name) method before getting values. For further info see this help topic

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Do you mean I need to count the null values seperately? – user5747 Feb 2 '12 at 16:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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