<?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 getting the field name in searchcursor through variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254895#M19592</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am doing a bulk spatial join on gps points by assigning the attributes within a site buffer to the points themselves.&amp;nbsp; Unfortunately, there are 4 different types of GPS points.&amp;nbsp; Within that, I only want to populate the most frequently occurring points(categories).&amp;nbsp; I have it set up with a stats table ordered by frequency.&amp;nbsp; From there, I am inserting the top 3 into a list, and then assigning as such. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is that because the ID field for the GPS points has a different name for each type.&amp;nbsp; When I go to grab the field from the search cursor, I'm forced to use an item.{variable} rather than item.fieldname.&amp;nbsp; It doesn't like that at all!&amp;nbsp; Is there a better way I could grab the field name from the table?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; I know it's a lot of code, but as I said, I'm just trying to find a way to grab the item.Columnname value from within the cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; 

towerfield = ["RNW","Cell","Scramble1","ServSN"]

def PQid():
&amp;nbsp;&amp;nbsp;&amp;nbsp; for value in towerfield:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print towerfield.index(value),value
&amp;nbsp;&amp;nbsp;&amp;nbsp; PQnum = input("Which field identifier is this carrier using?")
&amp;nbsp;&amp;nbsp;&amp;nbsp; PQKey = towerfield[PQnum]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return PQKey
Columnname = PQid()
arcpy.Statistics_analysis("FC_lyr", "F:/GIS Data/Drive Testing.gdb/stats", [["Device","COUNT"]], Columnname) #draw stats from inside feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; statstable = "F:/GIS Data/Drive Testing.gdb/stats"
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management(statstable).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print result
&amp;nbsp;&amp;nbsp;&amp;nbsp; Scursor = arcpy.SearchCursor("F:/GIS Data/Drive Testing.gdb/stats")#, "","", Statscolumn +&amp;nbsp; "; \"FREQUENCY\"", "COUNT_Device") #allow searching of stats table
&amp;nbsp;&amp;nbsp;&amp;nbsp; currentState = "" 
&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; Scursorfields = arcpy.ListFields(statstable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in Scursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("SelectedSite"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rt = (item.Frequency, str(item.Columnname),)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.append(rt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.reverse()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Apr 2013 15:02:42 GMT</pubDate>
    <dc:creator>StephenKruzik</dc:creator>
    <dc:date>2013-04-23T15:02:42Z</dc:date>
    <item>
      <title>getting the field name in searchcursor through variable</title>
      <link>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254895#M19592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am doing a bulk spatial join on gps points by assigning the attributes within a site buffer to the points themselves.&amp;nbsp; Unfortunately, there are 4 different types of GPS points.&amp;nbsp; Within that, I only want to populate the most frequently occurring points(categories).&amp;nbsp; I have it set up with a stats table ordered by frequency.&amp;nbsp; From there, I am inserting the top 3 into a list, and then assigning as such. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is that because the ID field for the GPS points has a different name for each type.&amp;nbsp; When I go to grab the field from the search cursor, I'm forced to use an item.{variable} rather than item.fieldname.&amp;nbsp; It doesn't like that at all!&amp;nbsp; Is there a better way I could grab the field name from the table?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&amp;nbsp; I know it's a lot of code, but as I said, I'm just trying to find a way to grab the item.Columnname value from within the cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; 

towerfield = ["RNW","Cell","Scramble1","ServSN"]

def PQid():
&amp;nbsp;&amp;nbsp;&amp;nbsp; for value in towerfield:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print towerfield.index(value),value
&amp;nbsp;&amp;nbsp;&amp;nbsp; PQnum = input("Which field identifier is this carrier using?")
&amp;nbsp;&amp;nbsp;&amp;nbsp; PQKey = towerfield[PQnum]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return PQKey
Columnname = PQid()
arcpy.Statistics_analysis("FC_lyr", "F:/GIS Data/Drive Testing.gdb/stats", [["Device","COUNT"]], Columnname) #draw stats from inside feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; statstable = "F:/GIS Data/Drive Testing.gdb/stats"
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management(statstable).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print result
&amp;nbsp;&amp;nbsp;&amp;nbsp; Scursor = arcpy.SearchCursor("F:/GIS Data/Drive Testing.gdb/stats")#, "","", Statscolumn +&amp;nbsp; "; \"FREQUENCY\"", "COUNT_Device") #allow searching of stats table
&amp;nbsp;&amp;nbsp;&amp;nbsp; currentState = "" 
&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; Scursorfields = arcpy.ListFields(statstable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in Scursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("SelectedSite"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rt = (item.Frequency, str(item.Columnname),)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.append(rt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.sort()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mylist.reverse()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 15:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254895#M19592</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2013-04-23T15:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: getting the field name in searchcursor through variable</title>
      <link>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254896#M19593</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are using the old cursor model (the non-data access kind), you will need to use the .getValue method if your field name is a variable. So for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fieldName = "TEST"
valueList = []
searchRows = arcpy.SearchCursor(myFC)
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; valueList.append(searchRow.getValue(fieldName))
del searchRow, searchRows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to use the newer data access cursor model (only available in v10.1+):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fieldName = "TEST"
valueList = []
searchRows = arcpy.da.SearchCursor(myFC,["*"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; valueList.append(searchRow[searchRows.fields.index(fieldName)])
del searchRow, searchRows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:35:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254896#M19593</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T12:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: getting the field name in searchcursor through variable</title>
      <link>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254897#M19594</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;getValue huh?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;well sir; you are correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am currently still on 10.0, so I did have to use the previous methods.&amp;nbsp; Worked like a charm though.&amp;nbsp; Thanks so much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Apr 2013 16:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-the-field-name-in-searchcursor-through/m-p/254897#M19594</guid>
      <dc:creator>StephenKruzik</dc:creator>
      <dc:date>2013-04-23T16:37:38Z</dc:date>
    </item>
  </channel>
</rss>

