Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

ArcGIS keeps throwing an error when I use the following script in the field calculator, using Python:

pre-logic script code:

y= ()
if !fieldx!.isalnum():
    y= 1
    y= 0



The error in the results window reads:

'ERROR 999999: Error executing function, Syntax Error, Failed to execture (CalculateField)'

I've checked the classes of the fields: fieldx is a string and fieldy a short integer, so that can't be the problem. I've also enabled the shapefile for editing. Note that I've added fieldy using the addfield function.

Other fieldcalculations, for example:

fieldy = 5

do work, so the problem should be in the syntax. What am I doing wrong? Any comments would be appreciated. Thanks in advance.

share|improve this question

migrated from Jan 29 '12 at 7:00

This question came from our site for professional and enthusiast programmers.

Is the !fieldx! notation something specific to arcgis? In standard Python, that would be the syntax error. – Thomas K Jan 26 '12 at 12:41
Hi Thomas, thanks for your consideration. Yes, I believe that's specific for ArcGIS. When I insert the fieldname by clicking the field from the field list, this is how it appears in the code. ArcGIS help docs also use this notation in their Python examples. – HDR Jan 26 '12 at 12:47

That needs to be treated as a function.

In your code block:

def AlnumField(field_value):
   if str(field_value).isalnum():
     return 1
     return 0

Then in your expression: AlnumField(!fieldx!)

The !fieldname! notation is only respected in the expression, not the code block.

share|improve this answer
In python the .isalnum() method is a string method. I'm not sure this will work if an int is provided as the field_value. – garnertb Jan 27 '12 at 20:11
Fixed, will now handle ints and friends. – Jason Scheirer Feb 28 '12 at 8:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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