Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using a Phython script 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?

import arcpy
import operator

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


stringList = [row.getValue(stringField) for row in arcpy.SearchCursor
                                       (inTable, "", "",stringField)]
share
1  
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

2 Answers 2

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

share
    
Do you mean I need to count the null values seperately? –  user5747 Feb 2 '12 at 16: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

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .