3

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)

  • 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
6

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")

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000

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.