codeblock @ arcpy.CalculateField_management

990
1
10-11-2013 01:32 AM
MarkusSchnitzius
New Contributor
Hi,

I have a table named "street" with a column named "Kategorie", filled with values "0..6". I added a new column named "RULE". I want to fill this column with strings depending on "KATEGORIE". I have a PY-Script and it doesn't work. What is wrong.
I think the problem is the line "expression" or "codeblock". I try to print the result of "myval".The result is a error message "name myval is not defined"

Thank you for your help !

expression = "getKat(!KATEGORIE!)"
codeblock = """def getKat(KATEGORIE):
    if KATEGORIE == "0":
        myval == "Autobahn"
    elif KATEGORIE == "1":
        myval == "Bundesstrasse"
    else:
        myval == "3"
    return myval"""
print "myval", myval
arcpy.CalculateField_management(ERG, "RULE", expression, "PYTHON", codeblock)



Tags (2)
0 Kudos
1 Reply
StephanieWendel
Esri Contributor
It looks like you were actually not assigning any values to myval. You had the double equals sign which is used to test equality not assign values. Try your code like this:


expression = "getKat(!KATEGORIE!)"
codeblock = """def getKat(KATEGORIE):
    if KATEGORIE == "0":
        myval = "Autobahn"
    elif KATEGORIE == "1":
        myval = "Bundesstrasse"
    else:
        myval = "3"
    return myval"""
print "myval", myval
arcpy.CalculateField_management(ERG, "RULE", expression, "PYTHON", codeblock)
0 Kudos