I'm working on a script to replace a layer datasource, and I'm getting an error I cannot figure out.

When I run the following code in a python window inside ArcMap, I get a "Runtime error : 'unicode' object is not callable"

import arcpy
mxd = arcpy.mapping.MapDocument ("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
     if lyr.supports("DATASOURCE"):
         if lyr.dataSource (r"N:\3_PLANNING\6_GIS\GIS Data\INDIANA GIS\Indiana_County.mdb\Boundaries\Indianacounty_shp"):
             lyr.replaceDataSource (r"N:\3_PLANNING\6_GIS\GIS Data\Indiana_County_Database_201201.gdb", "FILEGDB_WORKSPACE", r"N:\3_PLANNING\6_GIS\GIS Data\Indiana_County_Database_201201.gdb\Boundaries\County_Boundary")

Problem is, I'm not very good at python yet, and I'm not sure what the unicode object is that the error is referring to.

  • Can you please post the full stack trace? Is this all the code? What are you using to create the python script? – Jamie Jan 10 '13 at 15:56
  • Not sure what you mean by full stack trace. Yes, it is all the code. I'm just using the python window in ArcGIS and IDLE. – Chris Jan 10 '13 at 17:56

Turns out the issue was:

if lyr.dataSource (r"N:\3_PLANNING\6_GIS\GIS Data\INDIANA GIS\Indiana_County.mdb\Boundaries\Indianacounty_shp"):

it should be:

if lyr.dataSource == "N:\3_PLANNING\6_GIS\GIS Data\INDIANA GIS\Indiana_County.mdb\Boundaries\Indianacounty_shp":

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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