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|improve this question
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
add comment

2 Answers

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

share|improve this answer
    
Do you mean I need to count the null values seperately? –  user5747 Feb 2 '12 at 16:24
add comment

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
add comment

Your Answer

 
discard

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.