[GIS] Runtime error : ‘unicode’ object is not callable

arcpypython

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.

Best Answer

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":