[GIS] Putting multiple lines of Python into ArcGIS 10’s Field Calculator

arcgis-10.0arcgis-desktoperror-000539field-calculatorpython-parser

Entering these lines of Python one at a time works like a charm… Just need one more seemingly simply issue solved…

How do we place multiple lines of Python code into ArcGIS's Field Calculator without producing Error 000539 or syntax error?

I've tried several different syntaxes with colons and various spacings / returns …. screen shot:

enter image description here multiple lines of Python code here:

'1201-LT 210A' if !sc2! in (12013,11999,11998,12016,12015,12004,12012,12011,12001,12002,11997,12017,12009,12003) else !March_Proj!

'1201-LT 210B' if !sc2! in (12074,12076,12078,12072) else !March_Proj!

'1201-BO' if !sc2! in (20052,20053,20044,20045,20039,20050,20051,24157,24158,22927,24783,24785,24784,24782,24035,22924,23923,24154,22528,21912,23164) else !March_Proj!

'1202-LT 21F' if !sc2! in (1067,1066,1078,1060,1052,1075,1068,1051,1079,1062,1070,,1071) else !March_Proj!

Best Answer

I don't have ArcGIS 10 (yet), but from I read, you need to define a function:

def classify(value, default_value):
    if value in [14175,14161,14180,13459,13460,14652,14648,14647,14644]:
        return '1101A-BB 300B'
    elif value in [20077,20102,20106,20107,20165,20169,20170,20250,20263,20323,20327,20328,20462,20463,21871,24184,21167,21247,21248]:
        return '1101A-BO'
    elif value in [16708,16668,16669,16670,16698,16683,16700,16699,16709,16743,16742,16740,16739,16738,16706,16711,16701,16705,16713,16714,16693,16746]:
        return '1101A-LT_314'
    elif value in [21829]:
        return '1205-DFM DFDS362'
    # etc...
    else:
        return default_value

Then at the bottom (the next box), you would call the function:

classify(!sc2!, !March_Proj!)
Related Question