<?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 Calculate Field not working in arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575196#M45069</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure why this statement wouldn't run within an edit session in arcpy: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit = arcpy.da.Editor(gdb)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.startEditing(False, True)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.startOperation() &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.CalculateField_management ('Export_Output', 'Point_Type', 'UNKNOWN')&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.stopOperation()&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.stopEditing(True) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working with a versioned replica in SQL Express.&amp;nbsp; Working on the default version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Solution: I just ended up using da.UpdateCursor to calculate all recs to 'UNKNOWN'.&amp;nbsp; This worked fine.&amp;nbsp; Was getting strange results otherwise (on small and large datasets).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Jul 2016 09:33:20 GMT</pubDate>
    <dc:creator>SolanaFoo4</dc:creator>
    <dc:date>2016-07-27T09:33:20Z</dc:date>
    <item>
      <title>Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575196#M45069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure why this statement wouldn't run within an edit session in arcpy: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit = arcpy.da.Editor(gdb)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.startEditing(False, True)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.startOperation() &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.CalculateField_management ('Export_Output', 'Point_Type', 'UNKNOWN')&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.stopOperation()&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;edit.stopEditing(True) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working with a versioned replica in SQL Express.&amp;nbsp; Working on the default version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Solution: I just ended up using da.UpdateCursor to calculate all recs to 'UNKNOWN'.&amp;nbsp; This worked fine.&amp;nbsp; Was getting strange results otherwise (on small and large datasets).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 09:33:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575196#M45069</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-07-27T09:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575197#M45070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You forgot the quotes for the expression.&amp;nbsp; It needs to be '"UNKNOWN"'&amp;nbsp; Quotes are always the first thing to check whenever you do calculations, especially when they are run in a script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 14:26:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575197#M45070</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-07-27T14:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575198#M45071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So single quotes don't work here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:04:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575198#M45071</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-07-27T17:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575199#M45072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, that is not the problem.&amp;nbsp; It is that it must quote a quoted string, since the expression in the normal field calculator must be quoted.&amp;nbsp; "UNKNOWN" is what you should enter in the field calculator outside of a script.&amp;nbsp; Inside a script that quoted string needs to be quoted again to send it as a string value with quotes.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:18:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575199#M45072</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-07-27T17:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575200#M45073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I did use quotes, but just single quotes to quote the string.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:21:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575200#M45073</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-07-27T17:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575201#M45074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In a script you have to quote the expression regardless of what the value inside it contains (field names, numbers and strings all have to be in quotes).&amp;nbsp; So 'UNKNOWN' equates to an unknown value of UNKNOWN (no quotes) to the field calculator, which does not exist and causes an error.&amp;nbsp; You want to sent "UNKNOWN" (a quoted string), so you have to put that in quotes in the script, i.e., ' "UNKNOWN" ' (works for VB Script or Python calculations) or " 'UNKNOWN' " (works only for Python calculations).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:26:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575201#M45074</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-07-27T17:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575202#M45075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah okay!&amp;nbsp; Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 17:36:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575202#M45075</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-07-27T17:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575203#M45076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hm, I tried this: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit = arcpy.da.Editor(gdb)&lt;/P&gt;&lt;P&gt;edit.startEditing(False, True)&lt;/P&gt;&lt;P&gt;edit.startOperation() &lt;/P&gt;&lt;P&gt;# with arcpy.da.UpdateCursor('swXsectionPoint','Point_Type') as unk_csr:&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for unk_rec in unk_csr:&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unk_rec[0]="UNKNOWN"&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unk_csr.updateRow(unk_rec)&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management ("swXSectionPoint", "Point_Type", "UNKNOWN")&lt;/P&gt;&lt;P&gt;edit.stopOperation()&lt;/P&gt;&lt;P&gt;edit.stopEditing(True)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And it is still giving me strange results.&amp;nbsp; Tried doing it out of an edit session as well and still no luck.&amp;nbsp; Also, the Update Cursor shown commented out above seems to work.&amp;nbsp; Will put in a support request.&amp;nbsp; Perhaps I need to compress the gdb, or maybe I found a bug.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 18:50:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575203#M45076</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-07-27T18:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575204#M45077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do this for the calculation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;arcpy.CalculateField_management ("swXSectionPoint", "Point_Type", '"UNKNOWN"')&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;Notice that the expression cannot be "UNKNOWN", it must be '"UNKNOWN"' (single quote, double quote, UNKNOWN, double quote, single quote).&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #000000;"&gt;This assumes that swXSectionPoint is a layer recognized by the script and that Point_Type is a field in that layer.&amp;nbsp; There is no bug and support will tell you to write the calculation expression the same as what I have written in this post.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 18:56:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575204#M45077</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-07-27T18:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575205#M45078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah that did it!&amp;nbsp; Support thought it was a bug too, but they realized after looking further that it was a SQL issue.&amp;nbsp; I have no idea how this has not been an issue for me in the past.&amp;nbsp; I don't remember double-quoting my strings.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2016 18:31:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575205#M45078</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-08-12T18:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575206#M45079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting finding again, with this function. &amp;nbsp;Tried running:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.MakeFeatureLayer_management(fc,"cmpl","Material IN ('CMP',' CMP')")&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management("cmpl","Pipe_Material","'CMP'")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on some sde data unversioned (so no need to start an edit session). &amp;nbsp;It wouldn't run the calculate without error. &amp;nbsp;I had to add what they say is an optional parameter, expression_type:&amp;nbsp;&lt;SPAN&gt;"PYTHON_9.3" to make it run. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2016 01:05:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575206#M45079</guid>
      <dc:creator>SolanaFoo4</dc:creator>
      <dc:date>2016-09-14T01:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field not working in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575207#M45080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have gotten so used to Python not caring whether I&amp;nbsp;use single quotes or double quotes that I forgot you cannot use single quotes with VB Script. &amp;nbsp;In VB Script you have to write the calculation with escapes. &amp;nbsp;The following works&amp;nbsp;(determined by creating a model and exporting it to a Python script):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;arcpy.CalculateField_management("cmpl","Pipe_Material","\"CMP\"")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;Since this is not pure Python or pure VB Script it is not always easy to figure out where the Python parser of the script handles quotes and where the VB Script parser of the calculation handles quotes, so I usually build a model and export it to a Python script to get a reliable syntax.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2016 14:15:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-not-working-in-arcpy/m-p/575207#M45080</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2016-09-14T14:15:52Z</dc:date>
    </item>
  </channel>
</rss>

