<?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: Convert expression in Calculate Field from VB to PYTHON3 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1374605#M69726</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739827"&gt;@Rema&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;SPAN&gt;I'm not sure what th&lt;/SPAN&gt;&lt;SPAN&gt;e last argument (the empty one)&lt;/SPAN&gt;&lt;SPAN&gt; means&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can always check the reference t see what input the arcpy tools are expecting. In the case of the CalculateField function, the empty parameter is associated to the code block to be passed to the function.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check if this format works for you:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(FeatureClass1, 'test', """f"{len(!ClassRoomCd!)}"""", "PYTHON3")

# This one may not work because target field and the field used for calculation are the same!
arcpy.management.CalculateField(FeatureClass2, 'ClassRoomCd', """f"/ {!ClassRoomCd!}"""", "PYTHON3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jan 2024 19:24:40 GMT</pubDate>
    <dc:creator>Raul</dc:creator>
    <dc:date>2024-01-25T19:24:40Z</dc:date>
    <item>
      <title>Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367730#M69576</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm having trouble converting t&lt;/SPAN&gt;&lt;SPAN&gt;hese&lt;/SPAN&gt;&lt;SPAN&gt; expression to Python 3, could someone help me?&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.CalculateField_management(&lt;/SPAN&gt;&lt;SPAN&gt;Featureclass1&lt;/SPAN&gt;&lt;SPAN&gt;, "test", "Len( [ClassRoomCd] )", "VB", "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.CalculateField_management(&lt;/SPAN&gt;&lt;SPAN&gt;Featureclass2&lt;/SPAN&gt;&lt;SPAN&gt;, "ClassRoomCd", "&lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt;"0&lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt;"+ [ClassRoomCd]", "VB", "")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I tried the following expressions, but I got "the calculation tool is invalid" error.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.CalculateField_management(&lt;/SPAN&gt;&lt;SPAN&gt;Featureclass1&lt;/SPAN&gt;&lt;SPAN&gt;, "test", "Len(&lt;/SPAN&gt;&lt;SPAN&gt; !&lt;/SPAN&gt;&lt;SPAN&gt;ClassRoomCd&lt;/SPAN&gt;&lt;SPAN&gt;!&lt;/SPAN&gt;&lt;SPAN&gt; )", "&lt;/SPAN&gt;&lt;SPAN&gt;PYTHON&lt;/SPAN&gt;&lt;SPAN&gt;", "")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.CalculateField_management(&lt;/SPAN&gt;&lt;SPAN&gt;Featureclass2&lt;/SPAN&gt;&lt;SPAN&gt;, "ClassRoomCd", "&lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt;"0&lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt;"+ &lt;/SPAN&gt;&lt;SPAN&gt;!&lt;/SPAN&gt;&lt;SPAN&gt;ClassRoomCd&lt;/SPAN&gt;&lt;SPAN&gt;!&lt;/SPAN&gt;&lt;SPAN&gt;", "&lt;/SPAN&gt;&lt;SPAN&gt;PYTHON&lt;/SPAN&gt;&lt;SPAN&gt;", "")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I'm not sure what th&lt;/SPAN&gt;&lt;SPAN&gt;e last argument (the empty one)&lt;/SPAN&gt;&lt;SPAN&gt; means.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 09:20:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367730#M69576</guid>
      <dc:creator>Rema</dc:creator>
      <dc:date>2024-01-09T09:20:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367754#M69579</link>
      <description>&lt;P&gt;Dear Rema,&lt;/P&gt;&lt;P&gt;I hope you rae doing well,&lt;/P&gt;&lt;P&gt;you should pass block of the code in the empty one based on the expression which wyou provided.&lt;BR /&gt;please check the below link to see more in details.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I have attached a simple python script with a simple ArcGIS Project to the attachment.&lt;/P&gt;&lt;P&gt;This project is creating a new field and based on OBJECTID puts a value to the new created field.&lt;/P&gt;&lt;P&gt;Please find some screens of the project and Python script and output of the script.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MAP_1.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/90918i399452EDCD47CB7E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MAP_1.png" alt="MAP_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ATT_1.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/90919i65E97B5593136F49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ATT_1.png" alt="ATT_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Py_1.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/90917i4C85C9C88D560C45/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Py_1.png" alt="Py_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ATT_2.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/90916iAD4E7A2F5B16D8C5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ATT_2.png" alt="ATT_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;    &lt;/P&gt;&lt;P&gt;Good Luck&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 11:04:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367754#M69579</guid>
      <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
      <dc:date>2024-01-09T11:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367782#M69581</link>
      <description>&lt;P&gt;In python to get the size/length&amp;nbsp; &amp;nbsp;len&amp;nbsp; not Len&lt;/P&gt;&lt;P&gt;but that only works if the field is a text field, hence&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;len(!ClassRoomCd!&amp;nbsp;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;to add a 0 to the value, perhaps&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"'0' + len(!ClassRoomCd!) "&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;assuming that there are no blanks/nulls in the field&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 12:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1367782#M69581</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-01-09T12:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1374605#M69726</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/739827"&gt;@Rema&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;SPAN&gt;I'm not sure what th&lt;/SPAN&gt;&lt;SPAN&gt;e last argument (the empty one)&lt;/SPAN&gt;&lt;SPAN&gt; means&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can always check the reference t see what input the arcpy tools are expecting. In the case of the CalculateField function, the empty parameter is associated to the code block to be passed to the function.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check if this format works for you:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(FeatureClass1, 'test', """f"{len(!ClassRoomCd!)}"""", "PYTHON3")

# This one may not work because target field and the field used for calculation are the same!
arcpy.management.CalculateField(FeatureClass2, 'ClassRoomCd', """f"/ {!ClassRoomCd!}"""", "PYTHON3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 19:24:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1374605#M69726</guid>
      <dc:creator>Raul</dc:creator>
      <dc:date>2024-01-25T19:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383258#M69895</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dear &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="screens_38.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94995iD78B514FC3901482/image-size/large?v=v2&amp;amp;px=999" role="button" title="screens_38.png" alt="screens_38.png" /&gt;&lt;/span&gt;Amir Sarrafzadeh Arasi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your reply.&lt;BR /&gt;I tryed the script that you atatched, and that was educational!&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;The script was so simple that even I can understand.&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;I succeeded to fill a new field with&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;the values&amp;nbsp;&amp;nbsp;I defined in the script.&lt;BR /&gt;This experience motivated me to study python.&lt;BR /&gt;Thank you so much!&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 07:53:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383258#M69895</guid>
      <dc:creator>Rema</dc:creator>
      <dc:date>2024-02-16T07:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383261#M69896</link>
      <description>&lt;P&gt;Dear Rema,&amp;nbsp;&lt;BR /&gt;My Pleasure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Wishes&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 08:00:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383261#M69896</guid>
      <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
      <dc:date>2024-02-16T08:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert expression in Calculate Field from VB to PYTHON3</title>
      <link>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383262#M69897</link>
      <description>&lt;P&gt;Dear Raul&lt;BR /&gt;I'm sorry for thanking you so late.&lt;BR /&gt;That's what I wanted to know!&lt;BR /&gt;&lt;SPAN&gt;I read the link you atattched for me, and got what the "c&lt;/SPAN&gt;&lt;SPAN&gt;ode block" is.&lt;BR /&gt;&lt;/SPAN&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 08:04:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-expression-in-calculate-field-from-vb-to/m-p/1383262#M69897</guid>
      <dc:creator>Rema</dc:creator>
      <dc:date>2024-02-16T08:04:29Z</dc:date>
    </item>
  </channel>
</rss>

