I am attempting to Search Cursor through a joined table. (I do not have access to the original separated tables)
If the value of "COMPANY" and "DATE_" are then they will be skipped and it is suppose to pull the values from "COLLECTED_" (aka company) and "COLLECTION" (aka Date). Unfortunately it proceeding to overwrite the values with Null.
TOP: New Table of Result
BOTTOM: Original Joined Table of Data
import arcpy as ARCPY
from arcpy import env as ENV
#Environment(s)
workspaceTEST = r"C:\Users\Jim\Desktop\TESTSTRM_SWR.gdb"
ENV.workspace = workspaceTEST
#Variables
pipes15096 = workspaceTEST + "\PIPES_15096"
pipesOfficial = workspaceTEST + "\OFFICIAL_PIPES2015"
fieldsPipesOfficial = ["ID_NUMBER", "DATE_","COMPANY","COLLECTION","COLLECTED_"]
First Attempt:
valueDictOfficialPipes = {pipesRow[0]:(pipesRow[1:]) for pipesRow in ARCPY.da.SearchCursor(pipesOfficial, fieldsPipesOfficial)}
fieldsPipes15096 = ["ID" , "COLLECTION_DATE" , "COLLECTED_BY"]
with ARCPY.da.UpdateCursor(pipes15096, fieldsPipes15096) as updateRows_Pipes15096:
for updateRow2 in updateRows_Pipes15096:
keyValue2 = updateRow2[0]
print "keyValue2: ", keyValue2
print "updateRow2: ", updateRow2
if keyValue2 in valueDictOfficialPipes:
print "keyValue2 -V2: ", keyValue2
if valueDictOfficialPipes[1] and valueDictOfficialPipes[3] != ("<Null>" or " "):
for nullNoMore in range (1,len(fieldsPipes15096)):
updateRow2[nullNoMore] = valueDictOfficialPipes[keyValue2][nullNoMore-1]
print "updateRow2[nullNoMore]: ",updateRow2[nullNoMore]
updateRows_Pipes15096.updateRow(updateRow2)
print "updateRow2: ",updateRow2
del valueDictOfficialPipes
I attempted to split into to separate dictionaries and ran them, but the result was cause the second dictionary to overwrite the correction by the first.
#replace fieldsPipesOfficial with the following:
fieldsPipesOfficial_1 = ["ID_NUMBER", "DATE_", "COMPANY",]
# (ID) (DATE) (Collected By)
fieldsPipesOfficial_2 = ["ID_NUMBER", "COLLECTION","COLLECTED_"]
Second Attempt
valueDictOfficialPipes_1 = {pipesRow[0]:(pipesRow[1:]) for pipesRow in ARCPY.da.SearchCursor(pipesOfficial, fieldsPipesOfficial_1)}
fieldsPipes15096 = ["ID" , "COLLECTION_DATE" , "COLLECTED_BY"]
with ARCPY.da.UpdateCursor(pipes15096, fieldsPipes15096) as updateRows_Pipes15096:
for updateRow2 in updateRows_Pipes15096:
keyValue2 = updateRow2[0]
print "keyValue2: ", keyValue2
print "updateRow2: ", updateRow2
if keyValue2 in valueDictOfficialPipes_1:
print "keyValue2 -V2: ", keyValue2
if valueDictOfficialPipes_1[1] == ("<null>" or " "):
print "THERE SHOULD BE NO CHANGE"
else:
for nullNoMore in range (1,len(fieldsPipes15096)):
updateRow2[nullNoMore] = valueDictOfficialPipes_1[keyValue2][nullNoMore-1]
print "updateRow2[nullNoMore]: ",updateRow2[nullNoMore]
updateRows_Pipes15096.updateRow(updateRow2)
print "updateRow2: ",updateRow2
====================================
valueDictOfficialPipes_2 = {pipesRow[0]:(pipesRow[1:]) for pipesRow in ARCPY.da.SearchCursor(pipesOfficial, fieldsPipesOfficial_2)}
fieldsPipes15096 = ["ID" , "COLLECTION_DATE" , "COLLECTED_BY"]
with ARCPY.da.UpdateCursor(pipes15096, fieldsPipes15096) as updateRows_Pipes15096:
for updateRow2 in updateRows_Pipes15096:
keyValue2 = updateRow2[0]
print "keyValue2: ", keyValue2
print "updateRow2: ", updateRow2
if keyValue2 in valueDictOfficialPipes_2:
print "keyValue2 -V2: ", keyValue2
if valueDictOfficialPipes_2[1] == ("<null>" or " "):
print "THERE SHOULD BE NO CHANGE"
else:
for nullNoMore in range (1,len(fieldsPipes15096)):
updateRow2[nullNoMore] = valueDictOfficialPipes_2[keyValue2][nullNoMore-1]
print "updateRow2[nullNoMore]: ",updateRow2[nullNoMore]
updateRows_Pipes15096.updateRow(updateRow2)
print "updateRow2: ",updateRow2
del valueDictOfficialPipes_1
del valueDictOfficialPipes_2