<?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: CalculateField_management Expression Question in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691802#M53635</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're right!!&amp;nbsp; In the field calculator that's how the field names get labeled...&amp;nbsp; It does work now, just I have to be in edit mode because it gives me a cannot acquire a lock error, can this be avoided?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Sep 2013 18:24:42 GMT</pubDate>
    <dc:creator>GeoffOlson</dc:creator>
    <dc:date>2013-09-18T18:24:42Z</dc:date>
    <item>
      <title>CalculateField_management Expression Question</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691800#M53633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying understand the CalculateField_management tool and I guess I just don't understand how to properly define a field to be a variable.&amp;nbsp; I'm just working in the Python Window for now, attempting to get my expression to work.&amp;nbsp; I'm just using a test shapefile until I understand how the function works, so I just have "FIELD1", "FIELD2", "FIELD3", AND "FIELD4" and when I run my expression I receive an error saying it can't concatenate 'str' and 'int' objects. Obviously this is a problem because all of my attribute fields are set up as number fields, 1 and 2 are short and 3 and 4 are double.&amp;nbsp; So do I need a line to define each column as a number since it seems to be defaulting to strings?&amp;nbsp; Here is my line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CalculateField_management("pythontesting", "FIELD3", ("FIELD1" + 1) * "FIELD2", "PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That doesn't work, but if I replace my expression with 8 * 4, then I get the calculated value of 32.&amp;nbsp; What am I doing wrong?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2013 17:11:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691800#M53633</guid>
      <dc:creator>GeoffOlson</dc:creator>
      <dc:date>2013-09-18T17:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField_management Expression Question</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691801#M53634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Looks like a couple of things are causing you grief.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;First the entire expression should be in single quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management("pythontesting", "FIELD3", ' ("FIELD1" + 1) * "FIELD2" ', "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Second you specify PYTHON so your syntax for the expression should be PYTHON..get rid of the quotes on the fields in the expression...like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'(!FIELD1! +1)* !FIELD2!'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The text below should work&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management("pythontesting", "FIELD3", '(!FIELD1! + 1) * !FIELD2!', "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If not I would recommend using the Field calculator in ArcMap to test your expression, then you can port it to the python script.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2013 17:55:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691801#M53634</guid>
      <dc:creator>ScottRutzmoser2</dc:creator>
      <dc:date>2013-09-18T17:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField_management Expression Question</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691802#M53635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're right!!&amp;nbsp; In the field calculator that's how the field names get labeled...&amp;nbsp; It does work now, just I have to be in edit mode because it gives me a cannot acquire a lock error, can this be avoided?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2013 18:24:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691802#M53635</guid>
      <dc:creator>GeoffOlson</dc:creator>
      <dc:date>2013-09-18T18:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField_management Expression Question</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691803#M53636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I also found this from a thread a few years old, using an update cursor to be able to do the same thing but include an if statement so features get treated differently.&amp;nbsp; Thanks to Chris Snyder for his example snippet!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;updateRows = arcpy.UpdateCursor("pythontesting", "", "", "FIELD3")
updateRow = updateRows.next()
while updateRow:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if updateRow.FIELD1 == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow.FIELD3 = (updateRow.FIELD1 + 1) * updateRow.FIELD2
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updaterow(updateRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRow = updateRows.next()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691803#M53636</guid>
      <dc:creator>GeoffOlson</dc:creator>
      <dc:date>2021-12-12T05:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField_management Expression Question</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691804#M53637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are running it in ArcMap then you will likely need to be in an edit session...you can run it using the command line...try simply saving the file as somthing.py and then double clicking on it in windows explorer, a command prompt will open and run the script (make sure ArcMap is closed).&amp;nbsp; Or you can use a python ide like PyScripter (free) to run the script.&amp;nbsp; If you run it outside the ArcMap environment you shouldn't have an issue with a file lock, however, if you are running outside of ArcMap you will need to include the full path to the featureclass (first parameter).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Happy Scripting&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Sep 2013 19:04:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-expression-question/m-p/691804#M53637</guid>
      <dc:creator>ScottRutzmoser2</dc:creator>
      <dc:date>2013-09-18T19:04:45Z</dc:date>
    </item>
  </channel>
</rss>

