0

Very new to python, fairly experienced with ArcMap. I am trying to create an alphanumeric index based on point locations

My code string for the numeric part is here:

def calc(!LONG_x!):

    if !LONG_x! >= -113.90550 and !LONG_x! <= -113.90559:
        return "05"
    else:
        return "0"

I continue to get an error 000989 for syntax. What am I doing wrong?

3

You can't use punctuation marks in variable names in python. Your function should probably read more like this:

def calc(LONG_x):
    if LONG_x >= -113.90550 and LONG_x <= -113.90559:
        return "05"
    else:
        return "0"

You can then pass in !LONG_x! as an argument to the function.

eg. result = calc(!LONG_x!)

  • BruceDoh, That solved it. Thank you. I have Magnus Hetland's beginning python book. Does one find these syntax answers somewhere within its pages? – James Lambert Jul 21 '15 at 18:09
  • Right, I think the !FieldName! notation is specific to ArcGIS and isn't strictly Python proper. Magnus probably says somewhere in the book that variable names can only have letters, numbers, and underscores (no special characters) and can't begin with a number. – John Jul 21 '15 at 20:24
  • When solved, it is good idea to mark it as solved – FelixIP Jul 21 '15 at 21:54
  • And how do I mark it as solved? – James Lambert Jul 22 '15 at 20:00
  • Click the checkmark button under the up and down arrows. – BruceDoh Jul 22 '15 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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