Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Help with Calculate Field Management

$
0
0
I have this code setup properly (or so I think...) but get ERROR 000989. It would indicate that my syntax in the expression and/or codeblock is incorrect but it works within Arcmap on a single field. I am unsure how to fix this, any help would be greatly appreciated. Thanks!

Code:

import arcpy
import os, math
from arcpy import env

in_workspace = r"C:/"
fieldName = "Symbology"
expression = "Popclass(!Abbr!)"
codeblock = "def Popclass(City):\
    if MKE in City:\
        return 1\
    elif Madison in City:\
        return 2\
    elif Eau Claire in City:\
        return 3\
    else:\
        return 0"
for dirpath, dirnames, filenames in arcpy.da.Walk(in_workspace, datatype="FeatureClass",type="All"):
    if "skipFolder" in dirnames:
    for filename in filenames:
        if "Abbr" in [f.name for f in arcpy.ListFields(os.path.join(dirpath, filename))]:
            arcpy.AddField_management(os.path.join(dirpath,filename), fieldName, "SHORT", "", "", "", "", "NULLABLE")
            arcpy.CalculateField_management(os.path.join(dirpath,filename), "Symbology", expression, "PYTHON", codeblock)
        else:
            print "no Abbr field for dataset ", filename
print "message that reflected field calc use"
print "Finished script"


Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images