AnsweredAssumed Answered

Using python variables in SQL expression

Question asked by kviani on Mar 8, 2012
Latest reply on Mar 9, 2012 by kviani
I am trying to write something that describes assets with multiple locations and ranks the locations based on a road characterists.  I am basically building a list of the values that have multiple locations and then sending those values to a function that sorts and ranks those values.


#______________________________________________________________________ #define a function that takes the the assets with duplicate locations and assigns primary, secondary and so on based on the sorting of three fields #function takes the pid value and the full list of culvert locations  def setPrimLoc(pidV,CulvertLOC):     upExp="\"PID\" = " + str(pidV)     curUp = arcpy.UpdateCursor(CulvertLOC,upExp)     arcpy.Sort_management(CulvertLOC, "CULVsort", [[ "RT_TYPE","ASCENDING"], ["RT_RAMP","ASCENDING"],["RID_ETE","ASCENDING"]])     pl=1     for row in curUp:         row.PRIM_LOC = pl         pl+=1         curUp.updateRow(row)      # Delete cursor and row object     del row      del curUp   #______________________________________________________________________ #build a list of the ID numbers with multiple locations #outer loop that cycles through the circulates through the list of duplicate values #sends them to the function that sets primary location  curSch = arcpy.SearchCursor("CULVsort",MULTIPLEexpr)  pidLIST=[] for row in curSch:     if row.PID not in pidLIST:         pidLIST.append(row.PID) print pidLIST del curSch  val=0 for x in pidLIST:     print "Start outer"     pidV=pidLIST[val]     print x     sndLYR="LOC_LOAD_SGL_lyr"     exprPID="\"PID\""+"="+str(x)     arcpy.MakeFeatureLayer_management (CulvertLOC,sndLYR,exprPID)     setPrimLoc(x,sndLYR)     val+=1  


The error that I am comming up with is as follows:

       exprPID="\"PID\""+"="+str(x) TypeError: 'unicode' object is not callable 


Help me out I am beating myself up! Thanks

Outcomes