My programming is really rusty at this point, and I am trying to do a simple calculation using a Codeblock, either VB or Python is fine. I have tried about 50 different variations on same theme, and get a runtime error every time.

Here's a screenshot of my Field Calculator. Basically, Field !Items! contains a string of all items separated by a comma, and I am trying to create new fields that contain a "y" if that item is present in !Items!, in this case it's "Baby Items". It is always capitalized like so, no need to worry about case mismatch.

def calc (items)
  if items.find("Baby Items") != -1:
    return "y"

calc (!Items!)

Field Calc Screencap

  • Please include your code as text rather than a picture so that potential answered can copy/paste it for testing.
    – PolyGeo
    Commented May 10, 2017 at 20:26
  • You could find all the rows containing 'Baby Items' using items like '%Baby Items%' query and calculate baby = "y".. note the wildcard is different for data types, percent works for shapefiles and file geodatabases but for personal geodatabases use asterisk as the wildcard. see desktop.arcgis.com/en/arcmap/10.3/map/working-with-layers/… and search for LIKE. Note some data types have case sensitive SQL but some do not. Commented May 10, 2017 at 21:38

1 Answer 1


Almost there. Try this:

def calc(items):
    if "Baby Items" in items:
        return "y"

This will check for the string "Baby Items" contained in the field items.

Also remember the colon : after def calc(items) -> def calc(items):

  • Ahh, thanks, it was the colon after (items), I knew it was something ridiculous like that!!! I started using "in", and then kept re-inventing the wheel from there. Commented May 10, 2017 at 20:31
  • It won't let me upvote since I am a n00b here! Commented May 10, 2017 at 20:41

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.