<?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: Having trouble creating an expression for CalculateField() in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071104#M61441</link>
    <description>&lt;P&gt;I just tested a similar code snippet in Pro 2.8.0, and everything worked as expected, i.e., no error and expected results.&amp;nbsp; What desktop client and version are you using?&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jun 2021 18:04:02 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-06-22T18:04:02Z</dc:date>
    <item>
      <title>Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071094#M61440</link>
      <description>&lt;PRE&gt;arcpy.management.CalculateField(CAD_Anno&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"SymbolID"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"!SymbolID!.replace('0', '1')"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"PYTHON3"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here is the syntax I wrote and the corresponding Error. I'm decent at python, but I am so confused about how to get this expression working. Basically, in the field of "SymbolID" I want to replace all the 0s with 1s. So the pseudocode would be "If there is a 0 in this current row of the field SymbolID, then replace it with a 1"&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
File "C:/Users/ggroshans/Desktop/append.py", line 14, in &amp;lt;module&amp;gt;
arcpy.management.CalculateField(CAD_Anno, "SymbolID", "!SymbolID!.replace('0', '1')", "PYTHON3")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 5194, in CalculateField
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 5191, in CalculateField
retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type, enforce_domains), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000539: File "&amp;lt;expression&amp;gt;", line 1
0.replace('0', '1')
^
SyntaxError: invalid syntax

Failed to execute (CalculateField).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 17:46:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071094#M61440</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-06-22T17:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071104#M61441</link>
      <description>&lt;P&gt;I just tested a similar code snippet in Pro 2.8.0, and everything worked as expected, i.e., no error and expected results.&amp;nbsp; What desktop client and version are you using?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:04:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071104#M61441</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-06-22T18:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071107#M61442</link>
      <description>I am also on ArcGIS Pro 2.8.0. Not sure how yours worked and mine is&lt;BR /&gt;getting this error message.&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:05:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071107#M61442</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-06-22T18:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071114#M61443</link>
      <description>&lt;P&gt;How are you executing the code?&amp;nbsp; As a standalone script outside of Pro, a script tool in Pro, the interactive Python window in Pro, Jupyter notebook, etc...?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071114#M61443</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-06-22T18:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071118#M61444</link>
      <description>I'm executing it via standalone script in PyCharm. I have PyCharm connected&lt;BR /&gt;to the Python 3.7 (arcgispro-py3) environment.&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:15:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071118#M61444</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-06-22T18:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071123#M61445</link>
      <description>&lt;P&gt;The issue could be !SymbolID! is a numeric field.&lt;/P&gt;&lt;P&gt;Could you replace&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;"!SymbolID!.replace('0', '1')"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;with&lt;/P&gt;&lt;LI-CODE lang="python"&gt;str(!SymbolID!).replace('0','1')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:20:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071123#M61445</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2021-06-22T18:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071132#M61446</link>
      <description>&lt;P&gt;I tried converting it to string and got this error now:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GeoDev_0-1624386897578.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/16616i857EDC3C27AA2C31/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GeoDev_0-1624386897578.png" alt="GeoDev_0-1624386897578.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:35:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071132#M61446</guid>
      <dc:creator>GeoDev</dc:creator>
      <dc:date>2021-06-22T18:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071235#M61448</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;your field is type of Integer or string? if integer, you cannot&amp;nbsp; search and replace strings.&lt;/P&gt;&lt;P&gt;instead of calculcate field, you can also (which is faster by the way) use arcpy.da.UpdateCursor&lt;/P&gt;&lt;P&gt;if your field is integer, you can simply (within cursor) check if your value is equal to 0 or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 21:39:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071235#M61448</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2021-06-22T21:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble creating an expression for CalculateField()</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071243#M61449</link>
      <description>&lt;P&gt;I tried several stand-alone scripts that basically do the same thing your code does, and all of them work as expected.&lt;/P&gt;&lt;P&gt;Given the error message, and the fact I can't reproduce it, make sure you are not copying pasting single and double quotes from other applications because it may be what you think is a single or double quote is not and the Python interpreter is reading your code differently than you expect.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 21:52:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-creating-an-expression-for/m-p/1071243#M61449</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-06-22T21:52:45Z</dc:date>
    </item>
  </channel>
</rss>

