2

I'm having trouble with an error message and can't seem to figure out the reason which, I'm sure is something simple. I have a bit of code listed below:

insertPts = arcpy.da.InsertCursor(newFC, ( "FieldA", "FieldB"))

with arcpy.da.SearchCursor(FC, ("FieldA", "FieldB"),""" "FieldA" IS NOT NULL """) as search:
    for row in search:
        num = row[0]
        rPtsNumber = randint(1, row[0])
        row[0] = rPtsNumber
        PTSid = int(row[1])
        for x in xrange (num):
            insertPts.insertRow((rPtsNumber, PTSid))

the error occurs in the line 'for row in search:'. I though it may be an issue with the where clause however, I tried creating a new feature class based on the where clause criteria and continue to get the error. Thanks for any help you can provide.

1 Answer 1

1

This was a careless mistake on my part, I had been using the wrong FC variable in the search cursor. For this script I have too many variables with like names and confused 2 very important ones.

1
  • 1
    Good to know. Sometime's it's easier to assign your field as variables, that way should you need to re-use the script for different fields all you have to do is change the variable ex. field1 = "NameField" you would only have to change "NameField"
    – GISHuman
    Commented Aug 15, 2014 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.