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

I'm trying to calculate a field in Model Builder using the Calculate Field tool. I'm using the following code block and expression in the calculation, but am getting an "invalid syntax (, line 1)" error.

# Code Block:
def get_block(block_id):
    block_only = str(block_id)[1:]
    if block_only[-1].isalpha():
        return block_only.zfill(3)
        return block_only.zfill(2)

# Expression:

%block_id% is an in-line substitution that points to a string variable I create as the output of a custom Python script tool. Any ideas what the error is?

share|improve this question
up vote 2 down vote accepted

You need to quote the in-line substitution to pass the string variable.

The expression should read:




See the caution note in this help topic:

share|improve this answer
Ah, yes, that must be it. Will verify tomorrow when I'm back at work. Thanks! – nmpeterson Mar 11 '13 at 22:35
Just made the change and it worked perfectly. Thank you, again. – nmpeterson Mar 12 '13 at 13:44

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.