<?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 Re: Search Cursor - Search Entire Row? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295148#M22828</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Leigh,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That is essentially what I ended up doing, except your code looks a little cleaner. Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Sep 2011 17:34:45 GMT</pubDate>
    <dc:creator>BenYoungs</dc:creator>
    <dc:date>2011-09-07T17:34:45Z</dc:date>
    <item>
      <title>Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295142#M22822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This may be an obvious question but I am having a little trouble with this... I am writing a script to loop through all the feature classes in a given workspace, and I need to search all fields (or all string fields, at minimum) in each feature class based on a provided string. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Essentially, I need to do what the 'Find' command in ArcMap is supposed to do, except I need to run this automatically on hundreds or potentially thousands of feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been playing around with a Search Cursor to do this, but I havent been able to iterate through each field for every row of the table successfully. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am sure I could call the 'Select by Attributes' tool in Python and re-run that tool for each field in the feature class, but that seems inefficient to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone done anything like this before? Am I over-thinking this one and there is a simple solution?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using 9.3.1 in this instance but could write it for 10 if necessary. Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Sep 2011 20:38:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295142#M22822</guid>
      <dc:creator>BenYoungs</dc:creator>
      <dc:date>2011-09-06T20:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295143#M22823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Inside your SearchCursor loop, you should be able to loop through each field (or limit to string fields) with &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/ListFields/000v0000001p000000/"&gt;ListFields&lt;/A&gt;&lt;SPAN&gt; to test the value against your string. I have no idea if this is the fastest method or not.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Sep 2011 21:44:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295143#M22823</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-09-06T21:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295144#M22824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Inside your SearchCursor loop, you should be able to loop through each field (or limit to string fields) with &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/ListFields/000v0000001p000000/"&gt;ListFields&lt;/A&gt; to test the value against your string. I have no idea if this is the fastest method or not.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That was the first thing I tried. The problem that I was having was looping through each field for every row of the table:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for field in fieldlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.field == searchstring&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run this I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;'Row: Field field does not exist'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I can't use the field variable with the row. statement to search for a value. I'm not sure how I can get around that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 13:53:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295144#M22824</guid>
      <dc:creator>BenYoungs</dc:creator>
      <dc:date>2011-09-07T13:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295145#M22825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think you need to use &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000nv000000"&gt;getValue and setValue &lt;/A&gt;&lt;SPAN&gt;to work with field names as variables (not sure though).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 14:27:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295145#M22825</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-09-07T14:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295146#M22826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think this is what you're looking for.&amp;nbsp; This is a simple find and replace routine that will loop through every field of every row in your shapefile/feature class and make the necessary changes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;x = the value you want to find&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;y = the value you want to replace it with&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename = the file you're working on&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rows = arcpy.UpdateCursor(filename)
fields = arcpy.ListFields(filename)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue(field)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if value == x:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(field,y)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully, that at least gets you pointed in the right direction.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:10:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295146#M22826</guid>
      <dc:creator>LeighHolcombe</dc:creator>
      <dc:date>2021-12-11T14:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295147#M22827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think you need to use &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000nv000000"&gt;getValue and setValue &lt;/A&gt;to work with field names as variables (not sure though).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, that was part of my problem. I wasnt using the getValue, and I also was trying to use the field describe object instead of the field name specifically.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for field in fieldlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldname = field.Name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cell value = row.GetValue(field)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thats what worked for me. Thanks again for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 17:32:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295147#M22827</guid>
      <dc:creator>BenYoungs</dc:creator>
      <dc:date>2011-09-07T17:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Search Cursor - Search Entire Row?</title>
      <link>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295148#M22828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Leigh,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That is essentially what I ended up doing, except your code looks a little cleaner. Thanks for the help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 17:34:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/search-cursor-search-entire-row/m-p/295148#M22828</guid>
      <dc:creator>BenYoungs</dc:creator>
      <dc:date>2011-09-07T17:34:45Z</dc:date>
    </item>
  </channel>
</rss>

