1

Don't know for sure what is happening, but when I use arcpy.UpdateCursor it only writes some of the lines and not all of the lines.

The code is:

cursor = arcpy.UpdateCursor("FInal1a1.shp")
for row in cursor:
    row.setValue("NomArq",n)
    cursor.updateRow(row)
    with arcpy.da.SearchCursor("Final1a1.shp",['Id','Diametro','NomArq']) as Buscador:
        with open(nombarch2,"a+")as c:
            for row in Buscador:
                for cell in row:
                    conv= str(cell)
                    c.write(conv)
                    c.write(" ")
                c.write("\n")
            f.close

And the output is something like this: (it's the third row)

2 75 21 
2 75 0 
3 100 0 
3 100 0 
3 200 0 
2 75 21 
2 75 21 
3 100 0 
3 100 0 
3 200 0 
2 75 21 
2 75 21 
3 100 21 
3 100 0 
3 200 0 
2 75 21 
2 75 21 
3 100 21 
3 100 21 
3 200 0 
2 75 21 
2 75 21 
3 100 21 
3 100 21 
3 200 21 
2 90 32 
  • 1
    Since you're using a DA search cursor, why aren't you using a DA update cursor? Please update the question with the exact ArcGIS release. – Vince Jan 7 '15 at 12:04
  • 2
    you have two variables "row" with two different cursors and you update your row before you enter the search cursor in the same loop – radouxju Jan 7 '15 at 12:04
  • i already change the "row" variable but the script does the same... i will try with da.updatecursor right now – Gsanez Jan 7 '15 at 12:08
3

The reason is you put SearchCursor in the UpadteCursor's loop.

You can repair follow under code block.

cursor = arcpy.UpdateCursor("FInal1a1.shp")
for row in cursor:
    row.setValue("NomArq",n)
    cursor.updateRow(row)
with arcpy.da.SearchCursor("Final1a1.shp",['Id','Diametro','NomArq']) as Buscador:
    with open(nombarch2,"a+")as c:
        for row in Buscador:
            for cell in row:
                conv= str(cell)
                c.write(conv)
                c.write(" ")
            c.write("\n")
        f.close

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.