0

I have a code in which I'd like a da.UpdateCursor, I have probles with the "where clause", here I am about to use a variable that I get from arcpy.Describe. I have no idea of this even possible. My code is:

    newValue =  arcpy.GetParameterAsText(0)    
    inlyrdsc = arcpy.Describe("layertoedit")
    inFID = inlyrdsc.FIDset
    num = inFID.split("; ")

    inlayer = arcpy.mapping.Layer("layertoedit")
    query = "[OBJECTID] = %s", (num)
    fieldName = "fieldtoupdate"
    with arcpy.da.UpdateCursor(inlayer, (fieldName,), query) as cursor:
        for row in cursor:
            row[0] = newValue
            cursor.updateRow(row)

I get the following error message:

TypeError: 'where_clause' is not a string

Anyways my goal is to write a script which fills the attribute table of the selected element (the selection is described by the OBJECTID). This might not be the best solution so any ideas are welcomed.

  • The code that you are presenting does not seem to be the same code run to produce the error because it is missing any setting of the where_clause variable. – PolyGeo Sep 28 '15 at 10:08
  • 1
    Please remember to always include the feature class data source in your question, since different sources may have different SQL expression syntaxes. You should also use Data Access (da) cursors for all ArcGIS versions after 10.1. – Vince Sep 28 '15 at 10:29
1

num = inFID.split("; ") generates a python list. You maybe able to leave inFid ( a string of OIDs ) as is and use a query like query = "[OBJECTID] IN '{}'".format(inFid) Or instead of using an update cursor, just use CalculateField to set your new value on the selected set.

  • thanks for showing me the simplier way, CalculateField works fine. :) – buboreka Sep 28 '15 at 10:23

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.