I have a feature class within a file geodatabase.

I am using the "Iterate row selection" iterator in Model Builder to read each row in the FC. I am then using the "Get Field Value" tool to read the following 3 fields from each row:




I then want to use the "Calculate Value" tool to return a string, which I will later use as a file path to copy a specific file. The logic is as follows: If "Status" is "Available", return C:\Data\ + "Tile" otherwise return C:\Data\ + "Tile" + _ + "User"

In the Calculate Value tool, I've put the following into the expression field:

a("%Status%", "%User%", "%Tile%")

I've put the following into the Code Block:

def a(Status, User, Tile):
    if Status == "Available":
        return "C:\Data\" + Tile
        return "C:\Data\" + "Tile" + "_" + User

I have the "Data type" set as string.

My model is as follows:

enter image description here

I get the following error for my code block:

    ERROR 000989
Python syntax error: Parsing error SyntaxError: EOL while scanning string literal (line 3)

I'm happy to have a solution using model builder or using a stand along python script.

2 Answers 2


You should escape the \ character, this way:

def a(Status, User, Tile):
    if Status == "Available":
        return "C:\\Data\\" + Tile
        return "C:\\Data\\" + "Tile" + "_" + User

The problem, as indicated in gcarillo's answer, are the single \ characters, specially before the closing quote.

Some solutions:

  • Use / instead of \. Windows normally uses backslashes, but forward slashes work too except in the command prompt (cmd.exe).
  • Raw strings can be useful, but they don't help with strings that end in a backslash.
  • My favorite solution in cases like this: use os.path.join() instead of hardcoded path delimiters.

Example using os.path.join():

import os.path

def a(Status, User, Title):
    if Status == "Available":
        return os.path.join("C:", "Data", Tile)
        return os.path.join("C:", "Data", "Tile_" + User) # Or did you mean os.path.join("C:", "Data", Tile + "_" + User) ?

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.