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 would like to update the data source of a specific layer in multiple map documents using ArcPy, however I'm getting a <type 'exceptions.SyntaxError'>: invalid syntax error on this line:

if lyr.datasetName == inputlayer

import arcpy, string, os
import arcpy.mapping as MAP

    MXDList = string.split(arcpy.GetParameterAsText(0), ";") #ArcMap document(s)
    inputlayer = arcpy.GetParameterAsText(1) # featureclass
    newwork = arcpy.GetParameterAsText(2) # Workspace

    for MXDPath in MXDList:
        MXD = MAP.MapDocument(MXDPath)
        for dataframe in arcpy.mapping.ListDataFrames(MXD):
            lyrs = arcpy.mapping.ListLayers(dataframe)  
            for lyr in lyrs:
                if lyr.datasetName == inputlayer
                    lyr.replaceDataSource(newwork, "FILEGDB_WORKSPACE", "Center")

I must be missing something obvious here? I was attempting to reference this forum thread.

Thank You

share|improve this question
@blah238, thanks! – artwork21 Oct 13 '11 at 21:29
No problem, I'll convert it to an answer if that was the only problem! – blah238 Oct 13 '11 at 21:32
FYI the last line should be indented an additional 4 spaces but it won't let me make the edit. – blah238 Oct 13 '11 at 21:37
@blah238, Yes that is it. – artwork21 Oct 13 '11 at 22:06
up vote 4 down vote accepted

You're missing a colon. if lyr.datasetName == inputlayer:

share|improve this answer

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.