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 cobbled this code together from ESRI documentation and stackexchange answers.

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

1 Answer 1

up vote 5 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")

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

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.