<?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: Batch Calculate Field with ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485486#M70730</link>
    <description>&lt;P&gt;Right.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt; Thank you so much!!!&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2024 16:30:41 GMT</pubDate>
    <dc:creator>LoreleiPalmquist</dc:creator>
    <dc:date>2024-06-05T16:30:41Z</dc:date>
    <item>
      <title>Batch Calculate Field with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485477#M70727</link>
      <description>&lt;P&gt;I'm trying to step through a workspace and calculate all the fields that end in "Dep" to equal all the fields with matching field names (within the same feature class) minus the "Dep". However, it doesn't seem to like the {} method of putting a variable inside a string--it keeps saying "Invalid field {field}". Here's the code so far:&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;import arcpy&lt;/P&gt;&lt;P&gt;workspace = "G:/Layer/gdb/Layer.gdb"&lt;BR /&gt;features = []&lt;/P&gt;&lt;P&gt;# Walks through the workspace, appending every feature class's file&lt;BR /&gt;# location to the list "features."&lt;BR /&gt;walk = arcpy.da.Walk(workspace, datatype="FeatureClass")&lt;BR /&gt;for dirpath, dirnames, filenames in walk:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for filename in filenames:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; features.append(os.path.join(dirpath, filename))&lt;/P&gt;&lt;P&gt;# Calculates fields ending in "Dep" that match other fields to those matching&lt;BR /&gt;# fields' contents.&lt;BR /&gt;for feature in features:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;tempFields = arcpy.ListFields(feature)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for field in tempFields:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; compare = field.name + "Dep"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for i in tempFields:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if i.name == compare:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.management.CalculateField(feature, i.name, "!{field}!", 'PYTHON3')&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485477#M70727</guid>
      <dc:creator>LoreleiPalmquist</dc:creator>
      <dc:date>2024-06-05T16:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Calculate Field with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485482#M70728</link>
      <description>&lt;P&gt;You need to actually make it a formatted string. Add an f before the quotes.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;arcpy.management.CalculateField(feature, i.name, f"!{field}!", 'PYTHON3')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, please see here for posting code; it's easier to read if formatted: &lt;A href="https://community.esri.com/t5/community-help-documents/how-to-insert-code-in-your-post/ta-p/914552" target="_blank"&gt;How to insert code in your post - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:25:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485482#M70728</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-06-05T16:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Calculate Field with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485486#M70730</link>
      <description>&lt;P&gt;Right.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt; Thank you so much!!!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:30:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485486#M70730</guid>
      <dc:creator>LoreleiPalmquist</dc:creator>
      <dc:date>2024-06-05T16:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Calculate Field with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485487#M70731</link>
      <description>&lt;P&gt;Of course. Also, sorry I wrote that in a hurry and it came out terser than I meant.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:32:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485487#M70731</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-06-05T16:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Calculate Field with ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485488#M70732</link>
      <description>&lt;P&gt;No worries. I did the sweat emoji bc I'm a little embarrassed I forgot to make it a formatted string. I've forgotten most of what I've learned about programming (four years without doing any), and getting back into it feels like swimming upstream.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 16:35:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-calculate-field-with-arcpy/m-p/1485488#M70732</guid>
      <dc:creator>LoreleiPalmquist</dc:creator>
      <dc:date>2024-06-05T16:35:53Z</dc:date>
    </item>
  </channel>
</rss>

