Hi all, I am new to Python and trying to make an older piece of code work. It takes two tables, compares them, and if data in table A doesn't match table B it overwrites A with B.
If they are equal it leaves them alone...
dim intval
if [STR_NUM] = [SITUS_NR] then
intval = " "
else
intval = [STR_NUM]
end if
If it finds a "nil" in a field in table B it clears the field in table A
dim intval
if [STR_NUM] = "nil" then
intval = " "
else
intval = [SITUS_NR]
end if
Finally it overwrites table A if it finds data in table B
dim intval
if [STR_NUM] <> " " and [STR_NUM] <> "nil" then
intval = [STR_NUM]
else
intval = [SITUS_NR]
end if
Can anyone help me convert these or at least one to Python?
Thank you!
Solved! Go to Solution.
Following up on Dan Patterson's response:
It is also possible to do this in 1 line (without the codeblock section):
Also, it looks like you are trying to compare strings and store the result in a field that holds a string (result_field in the photos). If not, you may also need to do some type conversion:
[!STR_NUM!,""][!STR_NUM!==str(!SITUS_NR!)]
rvburton... most don't like the latter since it wasn't tried earlier (line 11 in my previous post), but they are definitely more elegant, if you can remember the generic, the specific is easy
Agreed. I hadn't noticed the [ False, True ][ Condition ] check before this post. It has a nice elegance to it, and it will come in handy. Thanks.
I'm looking forward to trying these suggestions on Monday!
Thank you Dan and Randy for helping me out! It works now! Another problem I had was that in shapefile form it would error "The field is not nullable". I had to put it in a geodatabase before the field calculations would work.