0

I am trying to make a python script for ArcGIS 9.3. I have a problem with the SetValue method. I try to use it in a very simple code but it still doesn't work : No error is return but my field is not populate. The code is the following :

import arcgisscripting
gp = arcgisscripting.create()

gp.workspace = r"Z:\PPR\PPR76\Tentative Macro Amelioration MNT"

try:

    input = gp.GetParameterAsText(0)
    field = "TEST"

    rows = gp.UpdateCursor(input)
    row = rows.Next()
    while row:
        expression = 3
        row.SetValue( field , expression)
        row = rows.Next()
except:
    print gp.GetMessages(2)

Thanks for your help

2

Instead of:

    rows = gp.UpdateCursor(input)
    row = rows.Next()
    while row:
        expression = 3
        row.SetValue( field , expression)
        row = rows.Next()

Try

    rows = gp.UpdateCursor(input)
    for row in iter(rows.next, None):
        expression = 3
        row.SetValue(field, expression)
        rows.updateRow(row)

Basically you forgot to call the updateRow method. That iter() trick isn't necessary, it just makes the code a little easier to read and lets you use a for loop.

  • I added : rows.updateRow(row) before row=rows.Next() and it worked. Thanks – Panvjim0 Mar 25 '14 at 14:47

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.