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 tried to use SearchCursor(points, fields=fieldname) but I get this error:

TypeError: SearchCursor() got an unexpected keyword argument 'fields'

I'm not sure why this doesn't work.

    # Local variables:
    points =  arcpy.MakeFeatureLayer_management("C:\\alltogether.shp")
    homebase_shp =  arcpy.MakeFeatureLayer_management("C:\\homebase.shp")

    fieldname = "Device"
    Device = arcpy.AddFieldDelimiters(points, fieldname)
    delimitedfield = arcpy.AddFieldDelimiters(points, fieldname)
    devices = set([row.getValue(fieldname) for row in arcpy.SearchCursor(points)])

    for i in devices:
            attr_sel = arcpy.SelectLayerByAttribute_management(points,"NEW_SELECTION", delimitedfield + " = " + str(i))
            totalpts = arcpy.GetCount_management(attr_sel)

            # Process: Select Layer By Location
            inside_sel = arcpy.SelectLayerByLocation_management(attr_sel, "WITHIN", homebase_shp, "", "SUBSET_SELECTION")
            insidepts = arcpy.GetCount_management(inside_sel)

            print "device %d has %d total points and %d inside the base" % (int(i),int(totalpts[0]),int(insidepts[0]))

a comment I saw earlier suggested doing it with fields=

Since you are only interested in one field, for better performance I would specify the >optional fields argument, e.g. myList = set([row.getValue(fldName) for row in >arcpy.SearchCursor(fcName, fields=fldName)]) – blah238 Jan 29 '12 at 1:03

Select distinct values from a single column of an attribute table (or layer)

share|improve this question
What version of arcgis are you working with? The API may have changed. – lynxlynxlynx Jan 31 '13 at 21:32
version 10.0. I assume thats what comment i pasted was using too since its arcpy.SearchCursor instead of arcpy.da.Searchcursor – EmdyP Jan 31 '13 at 21:43
up vote 6 down vote accepted

It looks like arcpy wants your arguments by position, not keyword. Therefore you would want to use something like:

SearchCursor(points, "","","fieldname")

If fieldname is a variable pointing to a string, omit the quotes. For multiple fields use:

SearchCursor(points, "","","Field1; Field2; Field3")

share|improve this answer

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.