<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using python variables in SQL expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3913#M328</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to write something that describes assets with multiple locations and ranks the locations based on a road characterists.&amp;nbsp; 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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#______________________________________________________________________ #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&amp;nbsp; def setPrimLoc(pidV,CulvertLOC): &amp;nbsp;&amp;nbsp;&amp;nbsp; upExp="\"PID\" = " + str(pidV) &amp;nbsp;&amp;nbsp;&amp;nbsp; curUp = arcpy.UpdateCursor(CulvertLOC,upExp) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Sort_management(CulvertLOC, "CULVsort", [[ "RT_TYPE","ASCENDING"], ["RT_RAMP","ASCENDING"],["RID_ETE","ASCENDING"]]) &amp;nbsp;&amp;nbsp;&amp;nbsp; pl=1 &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curUp: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.PRIM_LOC = pl &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pl+=1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curUp.updateRow(row)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Delete cursor and row object &amp;nbsp;&amp;nbsp;&amp;nbsp; del row&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; del curUp&amp;nbsp;&amp;nbsp; #______________________________________________________________________ #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&amp;nbsp; curSch = arcpy.SearchCursor("CULVsort",MULTIPLEexpr)&amp;nbsp; pidLIST=[] for row in curSch: &amp;nbsp;&amp;nbsp;&amp;nbsp; if row.PID not in pidLIST: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pidLIST.append(row.PID) print pidLIST del curSch&amp;nbsp; val=0 for x in pidLIST: &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Start outer" &amp;nbsp;&amp;nbsp;&amp;nbsp; pidV=pidLIST[val] &amp;nbsp;&amp;nbsp;&amp;nbsp; print x &amp;nbsp;&amp;nbsp;&amp;nbsp; sndLYR="LOC_LOAD_SGL_lyr" &amp;nbsp;&amp;nbsp;&amp;nbsp; exprPID="\"PID\""+"="+str(x) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management (CulvertLOC,sndLYR,exprPID) &amp;nbsp;&amp;nbsp;&amp;nbsp; setPrimLoc(x,sndLYR) &amp;nbsp;&amp;nbsp;&amp;nbsp; val+=1&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error that I am comming up with is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exprPID="\"PID\""+"="+str(x) TypeError: 'unicode' object is not callable &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Help me out I am beating myself up! Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Mar 2012 21:07:11 GMT</pubDate>
    <dc:creator>KevinViani</dc:creator>
    <dc:date>2012-03-08T21:07:11Z</dc:date>
    <item>
      <title>Using python variables in SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3913#M328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to write something that describes assets with multiple locations and ranks the locations based on a road characterists.&amp;nbsp; 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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#______________________________________________________________________ #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&amp;nbsp; def setPrimLoc(pidV,CulvertLOC): &amp;nbsp;&amp;nbsp;&amp;nbsp; upExp="\"PID\" = " + str(pidV) &amp;nbsp;&amp;nbsp;&amp;nbsp; curUp = arcpy.UpdateCursor(CulvertLOC,upExp) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Sort_management(CulvertLOC, "CULVsort", [[ "RT_TYPE","ASCENDING"], ["RT_RAMP","ASCENDING"],["RID_ETE","ASCENDING"]]) &amp;nbsp;&amp;nbsp;&amp;nbsp; pl=1 &amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curUp: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.PRIM_LOC = pl &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pl+=1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curUp.updateRow(row)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # Delete cursor and row object &amp;nbsp;&amp;nbsp;&amp;nbsp; del row&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; del curUp&amp;nbsp;&amp;nbsp; #______________________________________________________________________ #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&amp;nbsp; curSch = arcpy.SearchCursor("CULVsort",MULTIPLEexpr)&amp;nbsp; pidLIST=[] for row in curSch: &amp;nbsp;&amp;nbsp;&amp;nbsp; if row.PID not in pidLIST: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pidLIST.append(row.PID) print pidLIST del curSch&amp;nbsp; val=0 for x in pidLIST: &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Start outer" &amp;nbsp;&amp;nbsp;&amp;nbsp; pidV=pidLIST[val] &amp;nbsp;&amp;nbsp;&amp;nbsp; print x &amp;nbsp;&amp;nbsp;&amp;nbsp; sndLYR="LOC_LOAD_SGL_lyr" &amp;nbsp;&amp;nbsp;&amp;nbsp; exprPID="\"PID\""+"="+str(x) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management (CulvertLOC,sndLYR,exprPID) &amp;nbsp;&amp;nbsp;&amp;nbsp; setPrimLoc(x,sndLYR) &amp;nbsp;&amp;nbsp;&amp;nbsp; val+=1&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error that I am comming up with is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exprPID="\"PID\""+"="+str(x) TypeError: 'unicode' object is not callable &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Help me out I am beating myself up! Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2012 21:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3913#M328</guid>
      <dc:creator>KevinViani</dc:creator>
      <dc:date>2012-03-08T21:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using python variables in SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3914#M329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can't test this right now, so this is a shot in the dark, but I'd try replacing these two lines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;pidLIST.append(row.PID)&amp;nbsp; exprPID="\"PID\""+"="+str(x)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;With these&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;pidLIST.append(str(row.PID))&amp;nbsp; exprPID = "\"PID\" = " + x&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2012 21:15:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3914#M329</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-03-08T21:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using python variables in SQL expression</title>
      <link>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3915#M330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matt - Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure why but when I load the int values into the list and then retrive them through a for loop, they come back out as unicode values.&amp;nbsp; I don't know enough about what I'm am doing tounderstand why, but loading them to the list as string values worked perfectly.&amp;nbsp; Thanks for the tip.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Mar 2012 11:47:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-variables-in-sql-expression/m-p/3915#M330</guid>
      <dc:creator>KevinViani</dc:creator>
      <dc:date>2012-03-09T11:47:36Z</dc:date>
    </item>
  </channel>
</rss>

