<?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: Entire field populating with same value in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652871#M50852</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The logic of your cursor loop is flawed. You've created a list of &lt;EM&gt;filenames&lt;/EM&gt; and you enter the &lt;EM&gt;if&lt;/EM&gt; section of your code when it finds a name in &lt;EM&gt;names&lt;/EM&gt;. You then create an update cursor but you have not specified over what, so in this case the cursor defaults to ALL rows in the featureclass. You need to specify a whereclause when you create the cursor, something like &lt;STRONG&gt;field = '"' + filename + '"'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Aug 2014 15:12:56 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2014-08-08T15:12:56Z</dc:date>
    <item>
      <title>Entire field populating with same value</title>
      <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652870#M50851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am attempting to search directories and sub directories for file in 'name'&amp;nbsp; and return full file path of found file in a new field.&amp;nbsp; When I print the value of variable 'string' it prints the desired results However after the script runs the field is populated with a single value instead of unique values for each subsequent row.&amp;nbsp; Can anyone tell me why this is?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14075086874203560 jive_text_macro" jivemacro_uid="_14075086874203560" modifiedtitle="true"&gt;
&lt;P&gt;# Set local variable&lt;/P&gt;
&lt;P&gt;source = 'R:\\'&lt;/P&gt;
&lt;P&gt;fc = "I14__ATTACH_TEST"&lt;/P&gt;
&lt;P&gt;field = "ATT_NAME"&lt;/P&gt;
&lt;P&gt;addfieldName = "fullPath"&lt;/P&gt;
&lt;P&gt;fieldLength = 200&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Add field&lt;/P&gt;
&lt;P&gt;arcpy.AddField_management(fc, addfieldName, "TEXT", "", "", fieldLength)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;### Attempting to search directories and sub directories for file in 'name'&lt;/P&gt;
&lt;P&gt;###&amp;nbsp;&amp;nbsp;&amp;nbsp; and return full file path of found file (name)&lt;/P&gt;
&lt;P&gt;sc = arcpy.SearchCursor(fc)&lt;/P&gt;
&lt;P&gt;names = []&lt;/P&gt;
&lt;P&gt;for scrow in sc:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; names.append(scrow.getValue(field))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;for root, dirnames, filenames in os.walk(source):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if filename in names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string = os.path.join(root, filename)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.UpdateCursor(fc)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # field2 will be equal to field1 multiplied by 3.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(addfieldName, string)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cursor.next()&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 14:39:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652870#M50851</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2014-08-08T14:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Entire field populating with same value</title>
      <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652871#M50852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The logic of your cursor loop is flawed. You've created a list of &lt;EM&gt;filenames&lt;/EM&gt; and you enter the &lt;EM&gt;if&lt;/EM&gt; section of your code when it finds a name in &lt;EM&gt;names&lt;/EM&gt;. You then create an update cursor but you have not specified over what, so in this case the cursor defaults to ALL rows in the featureclass. You need to specify a whereclause when you create the cursor, something like &lt;STRONG&gt;field = '"' + filename + '"'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 15:12:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652871#M50852</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2014-08-08T15:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Entire field populating with same value</title>
      <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652872#M50853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply Duncan. Could you provide an example of this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 16:09:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652872#M50853</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2014-08-08T16:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Entire field populating with same value</title>
      <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652873#M50854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;your best examples of scripts is the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000014000000"&gt;online help files&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 16:18:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652873#M50854</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-08T16:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Entire field populating with same value</title>
      <link>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652874#M50855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks all for the input! Duncan your reply provided exactly what was needed. Here is what worked for me...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;whereClause = """"{}" = '{}'""".format(field, filename)&lt;/P&gt;&lt;P&gt;cursor = arcpy.UpdateCursor(fc, whereClause)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Noah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Aug 2014 19:40:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/entire-field-populating-with-same-value/m-p/652874#M50855</guid>
      <dc:creator>NoahHuntington</dc:creator>
      <dc:date>2014-08-08T19:40:19Z</dc:date>
    </item>
  </channel>
</rss>

