Select to view content in your preferred language

Trying to calculate values from two different tables using SearchCursor

753
3
11-09-2011 05:11 AM
DavidHarlan
New Contributor
It seems like this should be easy but my script is choking on something.  I have two dbf tables that each have a field "SUM_LENGTH".  I want to divide the value of one field by the other.  Each table only has one row so I thought next() would be appropriate to access the row and GetValue would return the value.  I am doing something wrong though.  Any ideas?

strcur = gp.SearchCursor(streamtable,"", "","SUM_LENGTH","")
Artcur = gp.SearchCursor(Arttable, "", "", "SUM_LENGTH", "")
strrow = strcur.next()
artrow = Artcur.next()
strlen = strrow.GetValue("SUM_LENGTH")
artlen = artrow.GetValue("SUM_LENGTH")

index = artlen / strlen
print index
del Artcur
del strcur

#thanks
Tags (2)
0 Kudos
3 Replies
ChrisSnyder
Regular Contributor III
getvalue() is for retreiving values when the field name is stored as a variable. In your case, you don't need it, since you already know the field name.

Since there is only a single record in the tables, how about:

strlen = gp.SearchCursor(streamtable,"", "","","").next().SUM_LENGTH
artlen = gp.SearchCursor(Arttable,"", "","","").next().SUM_LENGTH
index = artlen / float(strlen)
print index
del strlen, artlen
0 Kudos
DavidHarlan
New Contributor
Thanks a bunch Chris.  I'm pretty new at this and as usual I'm making it more complicated that it needs to be.  Python is a harsh mistress, yes?
0 Kudos
ChrisSnyder
Regular Contributor III
Harsh at first perhaps.... Once you understand her though, she is a real gem 😉
0 Kudos