how to use database in python code example
Example: python build dictionary for use in table join
from time import strftime
print "Start script: " + strftime("%Y-%m-%d %H:%M:%S")
import arcpy
sourceFC = r"C:\Path\SourceFeatureClass"
sourceFieldsList = ["JoinField", "ValueField"]
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
updateFC = r"C:\Path\UpdateFeatureClass"
updateFieldsList = ["JoinField", "ValueField"]
with arcpy.da.UpdateCursor(updateFC, updateFieldsList) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in valueDict:
updateRow[1] = valueDict[keyValue][0]
updateRows.updateRow(updateRow)
del valueDict
print "Finished script: " + strftime("%Y-%m-%d %H:%M:%S")