<?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: Calculation string field with python in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/calculation-string-field-with-python/m-p/157221#M5272</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management (filename2, "Description", filename1, "VB","") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What you were telling the tool is that your expression was the string 'filename1' not the value of the variable filename1. The easiest thing to do in Calculate Field is to do all of your calculations outside the tool syntax and then plug the value in with a variable. Also python code blocks in CF are tricky and can be a mess to debug as well so I try to avoid using them if I can.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Sep 2010 20:16:01 GMT</pubDate>
    <dc:creator>ChrisMathers</dc:creator>
    <dc:date>2010-09-20T20:16:01Z</dc:date>
    <item>
      <title>Calculation string field with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculation-string-field-with-python/m-p/157220#M5271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hallo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i have a problem with calculating a field with a string variable. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The string variable is the filename1. But the field description doesn´t take take the string value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PYTHON CODE:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fclist = gp.ListFeatureClasses("*", "Polygon")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for featureclass in fclist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = str(featureclass)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # setting filenames and pathvars&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename1 = os.path.splitext(featureclass)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print filename1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; pathvar1 = ReferenceWorkspace + "\\" + filename1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filename2 = OutputLocation + "\\" + filename1 + "_Dissolve"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Dissolve selected attirbute field&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Dissolve_management (featureclass, filename2, DissolveField)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; OutputLocation = gp.Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add Field Description and calculate Description with file name &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management (filename2, "Description", "TEXT","","","30" )&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management (filename2, "Description", 'filename1', "Python","")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Sep 2010 18:24:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculation-string-field-with-python/m-p/157220#M5271</guid>
      <dc:creator>HolmSeifert</dc:creator>
      <dc:date>2010-09-20T18:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation string field with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculation-string-field-with-python/m-p/157221#M5272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management (filename2, "Description", filename1, "VB","") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What you were telling the tool is that your expression was the string 'filename1' not the value of the variable filename1. The easiest thing to do in Calculate Field is to do all of your calculations outside the tool syntax and then plug the value in with a variable. Also python code blocks in CF are tricky and can be a mess to debug as well so I try to avoid using them if I can.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Sep 2010 20:16:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculation-string-field-with-python/m-p/157221#M5272</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2010-09-20T20:16:01Z</dc:date>
    </item>
  </channel>
</rss>

