Code sample below:
< dyn emptystr=" " property="PageNumber_E" type="page" >
< dyn emptystr=" " property="PageNumber_E" type="page" >
####################
# Input Parameters #
####################
inputTable = arcpy.GetParameterAsText(0)
CountFields = arcpy.GetParameterAsText(1)
VotedValues = arcpy.GetParameterAsText(2)
###################
# Local Variables #
###################
ElectionCountFieldName= "ElectionCount"
###################
# Logic #
###################
fields = arcpy.ListFields(inputTable)
for field in fields:
if field.name == ElectionCountFieldName:
arcpy.DeleteField_management(inputTable, ElectionCountFieldName)
break
del fields
arcpy.AddField_management(inputTable, ElectionCountFieldName, "TEXT")
rows = arcpy.UpdateCursor(inputTable)
splitVal = VotedValues.split(',')
for row in rows:
count = 0
for f in CountFields:
if str(row.getValue(f)) in splitVal:
count = count + 1
row.setValue(ElectionCountFieldName,str(count))
rows.updateRow(row)
del row, rows
arcpy.SetParameterAsText(3, inputTable)
Parameter | Name | Setup |
1 | Input Table/FC | Type: Feature Class or Table |
2 | Fields | Type: Field, Obtained From: Parameter 1, MultiValue: Yes |
3 | Voted Values | Type: String |
4 | Return Table/FC | Type: Table/FC, Direction: Output |