Expression
Terry Reedy
tjreedy at udel.edu
Tue Apr 7 18:22:01 EDT 2009
Lydia wrote:
> I am working on calculating one of the fields in a feature class based
> on other 2 fields. The logic is,
> A (the resulting field) is calculated from B, but C and D have part of
> the value that could fill the blank of B, which meaning that combine
> three fields of values can make A.
>
> Field A is what I need.
>
> The data looks like: .
>
> A B C D
> 2 2
> 5 5
> 4 4
> 6 6
>
>
> cur = gp.UpdateCursor(data)
> row = cur.Next()
> gp.CalculateField_management(data, "A", "[B]", "VB", "")
Those indents are wrong, and would cause a syntax error, so this must
not be the code you actually ran. When posting, please copy and paste
instead of retyping.
Does the last line set A from B? Should it be inside the loop?
> while row:
>
> cur.UpdateRow(row)
Or does this magically set A from B?
>
> if not(row.GetValue("C") == 'NULL'):
This should be the same as
if row.GetValue("C") != 'NULL':
which I find easier to read.
From what you said before, you only want to set A from C or D if B is
blank. If so, this section should be indented under
if row.GetValue("B") == 'NULL':
> row.SetValue("A",row.GetValue("C"));
>
> elif not(row.GetValue("D") == 'NULL'):
> row.SetValue("A",row.GetValue("D"));
>
> row = cur.Next()
>
> del cur
> del row
Again, indent is erroneous.
> But the out looks like only B was calculated to A successfully. C&D are
> not in A.
I have no idea why not. A main way to debug is to insert print
statements into the code in appropriate places and see if what is
printed matched what you expect.
> I guess there must be something wrong with the code, but I am very new
> to Python, and not familiar with the expression. Could anybody help ?
> PS. I am coding Python with ARCGIS.
I am not familiar with ARCGIS.
tjr
More information about the Python-list
mailing list