On 02/09/2010 23:01, Nally Kaunda-Bukenya wrote:
Dear all, kindly help me with this code;
This script is supposed to calculate Rvi for each row by first summing
the product of #fields (Ai*Rv) and dividing by another field (Tot) such
that Rvi=sum(Ai*Rv)/Tot. First it's acting like I need another
parenthesis and it doesn't seem to work at all. i even imported the math
module, but not sure if a need it. Please advice, your help is highly
appreciated. Please see the code below:
import arcpy, math
arcpy.Workspace = "C:\\data\\basins.mdb"
fc = "wshed"
sum = 0

It looks like you're using 'sum' as a variable. Bad idea. That hides
the 'sum' function which you need later.

# Create the update cursor and advance the cursor to the first row
cur = arcpy.UpdateCursor(fc)
row = cur.Next()
# Perform the update and move to the next row as long as there are
# rows left
for row:

Syntax error. It's:

    for variable in iterator:
        ...

row.GetValue(Rvi) = sum(row.Ai*row.Rv)/row.ATot

Assign to the result of row.GetValue(Rvi)? Is that right? I don't know
arcpy, but somehow that doesn't look right to me.

cur.UpdateRow(row)
row = cur.Next()
# Delete the cursors to remove any data locks
del row, cur

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to