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!
  • Can you post the whole code you are using since it seems to fail on the first field in your table that contains a null value and seems to partially calculate values for the destination field that have values in the first field.
    – user681
    Mar 13, 2011 at 21:36
  • Thanks for the response Dan. All of the code is here: link If i enter the lines one by one and hit ok in Field Calculator they work fine.... just would like to do them all at once since i will being hundreds more.
    – sirgeo
    Mar 13, 2011 at 21:59

1 Answer 1


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...
        return default_value

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

classify(!sc2!, !March_Proj!)
  • Thanks Mike, i just tried (twice) entering that code and arcmap goes into a some sort of a loop and has to be killed in task manager.... i tested it by simply deleting the # etc... and the ensuing empty line. and leaving everything else alone... is !March_Proj! highlighted in blue for any particular reason?
    – sirgeo
    Mar 13, 2011 at 22:39
  • Ah, I had two syntax errors: I forgot the ":" at the end of two statements. They are fixed in the above, so you can test it out again. The # etc... is a harmless comment, and I'm not sure why gis.se's syntax highlighter is marking !March_Proj! with blue text, but it shouldn't make any difference in the end.
    – Mike T
    Mar 13, 2011 at 23:02
  • Mike, when i input the code you have listed above it works perfectly... somewhere when i populated the rest of it there's a glitch (beyond the 8 or so syntax errors i corrected from my imperfect copy / paste methods)... the error screen shot i keep getting here: link the entire code here: link i am putting it all in pre-logic minus the end piece classify(!sc2!, !March_Proj!) which goes in the bottom.
    – sirgeo
    Mar 14, 2011 at 0:02
  • You had a special case where you were comparing one item: value in (21829) is incorrect, but value in (21829,) is correct. The reason is that you are creating "tuples" on the right-hand side, and tuples can have a tricky syntax. A list could also work, which looks like [21829]. I've added this case example to the above code. You can debug the function directly in PythonWin to find what line-number the error happens on.
    – Mike T
    Mar 14, 2011 at 0:26
  • Actually, I changed the example to use lists (rather than tuples), since the tuple exception is a silly distraction. Python lists are normally a lot more useful anyways.
    – Mike T
    Mar 14, 2011 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.