<?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: Python Scrip that Copies Data in a Field to another Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486959#M38020</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;awsome... this worked... arcpy.CalculateField_management(eco_pa, "OCCUR", "!" + fname + "!", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it didn't like reading it in as a string... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ian&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Apr 2012 16:38:22 GMT</pubDate>
    <dc:creator>IanLeinwand</dc:creator>
    <dc:date>2012-04-30T16:38:22Z</dc:date>
    <item>
      <title>Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486955#M38016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to copy data from one field to another field within a loop. The issue I'm having is how to define the field from which data is being copied as a&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;variable. The field name from which I want to copy data changes with each iteration of the loop based on the input datasets name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code and I highlighted where I'm having trouble... I either get an error or the data does not copy but the script runs... depends on how I s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;specify the field name variable. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See... arcpy.CalculateField_managment section of the code &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# combine_ecoregion_tree_species.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Created on: 2012-04-25 09:17:22.00000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# (generated by ArcGIS/ModelBuilder)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Description: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = r"\\Sxftcsls001\m\SDL\Data\Forest_Parameters\FHTET\240m\20111019_L48"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rasterList = arcpy.ListRasters("*", "GRID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;listCount = len(rasterList)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print listCount&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for r in rasterList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if(r.startswith ("f")):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print r&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; # Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; OutWorkspace = "D:\\Risk_Models\\Ecoregion_Tree_Species\\"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; eco_id = "D:\\Risk_Models\\Ecoregion_Tree_Species\\eco_id"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Extent = "-2370945 255315 2273055 3189315"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; snap = "\\\\Sxftcsls001\\m\\SDL\\Data\\Snap_Grids\\FHTET\\240m\\L48\\snap"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; species_pa = OutWorkspace + r&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; eco_pa = OutWorkspace + "eco_" + r&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; species_field = str(r)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print r&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print " species code is " + species_field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; # Process: Con&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.env.snapRaster = snap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.env.extent = Extent&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.gp.Con_sa(r, 1, species_pa, 0, "\"VALUE\" &amp;gt; 0")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; # Process: Combine&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.gp.Combine_sa([species_pa,eco_id], eco_pa)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print "combine complete"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; # Process: Add Field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddField_management(eco_pa, "SPECIES", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.AddField_management(eco_pa, "OCCUR", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print "add field"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_management(eco_pa, "SPECIES", "species_field", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print "Calculate Species Field"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; fields = arcpy.ListFields(eco_pa)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fieldnames = [f.name for f in fields]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; fname = fieldnames[3]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print fname&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; fname_calc = [str(fname)]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print fname_calc&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print fieldnames&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_management(eco_pa, "OCCUR", "%s" %fname_calc, "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; print "calculated Field"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 15:23:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486955#M38016</guid>
      <dc:creator>IanLeinwand</dc:creator>
      <dc:date>2012-04-30T15:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486956#M38017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to wrap field names in !'s when they are used in the field calculator expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.CalculateField_management(eco_pa, "OCCUR", "!" + fname_calc + "!", "PYTHON")
 &lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Tip: make your calculation in the ArcMap field calculator and look at the results to see the proper syntax.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486956#M38017</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T21:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486957#M38018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You need to wrap field names in !'s when they are used in the field calculator expression.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.CalculateField_management(eco_pa, "OCCUR", "!" + fname_calc + "!", "PYTHON")
 &lt;/PRE&gt;&lt;BR /&gt;Tip: make your calculation in the ArcMap field calculator and look at the results to see the proper syntax.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks... I'm trying that now... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created a model in model builder with the calculate field tool set do do the calculation I wanted and exported that to python... it did not give me the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;correct syntax. It had the field wrapped in [ ]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your response... I'll let you know how it goes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:26:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486957#M38018</guid>
      <dc:creator>IanLeinwand</dc:creator>
      <dc:date>2021-12-11T21:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486958#M38019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just tried that and got an error saying it can't concatenate string and list objects.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 16:31:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486958#M38019</guid>
      <dc:creator>IanLeinwand</dc:creator>
      <dc:date>2012-04-30T16:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486959#M38020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;awsome... this worked... arcpy.CalculateField_management(eco_pa, "OCCUR", "!" + fname + "!", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it didn't like reading it in as a string... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ian&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 16:38:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486959#M38020</guid>
      <dc:creator>IanLeinwand</dc:creator>
      <dc:date>2012-04-30T16:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Python Scrip that Copies Data in a Field to another Field</title>
      <link>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486960#M38021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, yeah. I'm not sure what it's trying to accomplish with "fname_calc = [str(fname)]". What I am sure about is this: the script produced by exporting from ModelBuilder is a lie.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Apr 2012 16:41:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-scrip-that-copies-data-in-a-field-to/m-p/486960#M38021</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-30T16:41:07Z</dc:date>
    </item>
  </channel>
</rss>

