<?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: How to run the Calculate Field using ArcPy? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1135392#M63544</link>
    <description>&lt;P&gt;Seems like you saved the unicode symbol and the double quotes as actual text.&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# define a function that will convert 'u"1234_5678"' to '1234_5678'
# CalculateField needs it as string
code_block = """
def clean_up(text_value):
    if text_value.startswith('u"'):
        text_value = text_value[1:]  # remove unicode symbol
    return text_value.replace('"', '')  # remove double quotes
"""

func_1 = "clean_up(!AttArt_Ken!).split('_')[0]"  # without single quotes around the field name!
field_1 = "ObjArt_Ken"

func_2 = "clean_up(!AttArt_Ken!).split('_')[1]" # without single quotes around the field name!
field_2 = "Wert"

arcpy.AddField_management(inTable, field_1, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_1, func_1, "PYTHON_9.3", code_block)

arcpy.AddField_management(inTable, field_2, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_2, func_2, "PYTHON_9.3", code_block)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 20 Jan 2022 13:10:40 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-01-20T13:10:40Z</dc:date>
    <item>
      <title>How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130751#M63401</link>
      <description>&lt;P&gt;I have an issue in executing the Calculate field command in Python (ArcPy). I couldn't find any related resources or helpful descriptions regarding this. I hope somebody could help me with this.&lt;/P&gt;&lt;PRE&gt;inFeatures = r"H:\Python Projects\PycharmProjects\ArcPy\Test_Output\Trial_out.gdb\Trail_Data_A.shp"


arcpy.CalculateField_management(inFeatures, 'ObjArt_Ken', '!AttArt_Ken!'.split('_')[0])
arcpy.CalculateField_management(inFeatures, 'Wert', '!AttArt_Ken!'.split('_')[-1])&lt;/PRE&gt;&lt;P&gt;The error &lt;A href="https://www.olehanakorea.com/" target="_self"&gt;i&lt;/A&gt; am getting when I run the command is&lt;/P&gt;&lt;PRE&gt;arcgisscripting.ExecuteError: Error during execution. Parameters are invalid.
ERROR 000989: The CalculateField tool cannot use VB expressions for services.
Error while executing (CalculateField).&lt;/PRE&gt;&lt;P&gt;I am using ArcGIS Pro 2.8 and Python 2.7&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 12:32:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130751#M63401</guid>
      <dc:creator>ShaistaBaloch</dc:creator>
      <dc:date>2022-01-05T12:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130769#M63402</link>
      <description>&lt;P&gt;You can find the documentation for the tool here:&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" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CalculateField has the following signature:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(in_table, field, expression, {expression_type}, {code_block}, {field_type}, {enforce_domains})&lt;/LI-CODE&gt;&lt;P&gt;expression_type is an optional argument specifying the language you want to use (Python, Arcade, SQL), with Python being the default.&lt;/P&gt;&lt;P&gt;Now here is where it gets fishy: You said you were working with ArcGIS Pro, but the error you got says you are using VB as the language for CalculateField. This would make sense, as VB is the default value for CalculateField &lt;STRONG&gt;in ArcMap&lt;/STRONG&gt; (which also uses Python 2.7, while Pro uses Python 3). Something doesn't check quite out...&lt;/P&gt;&lt;P&gt;There are some other problematic things with your code:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;your in_features seem to be in a file geodatabase (gdb), but you still specified the .shp extension. don't know if that will cause an error (I hope it will).&lt;/LI&gt;&lt;LI&gt;the docs (see link above) specify that for Python code, you should enclose field names with &lt;STRONG&gt;!&lt;/STRONG&gt;, you use &lt;STRONG&gt;'!&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;the expression&amp;nbsp; is given as a string, and your Python expression&amp;nbsp; will be wrong, as you didn't enclose it in quotes.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Try using this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;inFeatures = r"H:\Python Projects\PycharmProjects\ArcPy\Test_Output\Trial_out.gdb\Trail_Data_A" # removed the .shp

expr_1 = "!AttArt_Ken!.split('_')[0]" # note the enclosing "
expr_2 = "!AttArt_Ken!.split('_')[-1]" # note the enclosing "

# for ArcMap &amp;amp; Python 2.7
arcpy.CalculateField_management(inFeatures, 'ObjArt_Ken', expr_1, "PYTHON")
arcpy.CalculateField_management(inFeatures, 'Wert', expr_2, "PYTHON")

# for ArcGIS Pro and Python 3:
arcpy.CalculateField_management(inFeatures, 'ObjArt_Ken', expr_1, "PYTHON3")
arcpy.CalculateField_management(inFeatures, 'Wert', expr_2, "PYTHON3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:19:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130769#M63402</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-05T13:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130770#M63403</link>
      <description>&lt;P&gt;For completeness, here's the doc for ArcMap:&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:21:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1130770#M63403</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-05T13:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1131118#M63412</link>
      <description>&lt;P&gt;Your file path is&amp;nbsp;r"...\Trial_out&lt;STRONG&gt;.gdb&lt;/STRONG&gt;\Trail_Data_A&lt;STRONG&gt;.shp&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;This will never work.&amp;nbsp; You appear to have saved a shapefile&amp;nbsp;into a .gdb folder that while it is just a folder to Windows, is not treated as a folder by ArcGIS, but as a&amp;nbsp;file geodatabase. ArcGIS does not recognise non-file geodatabase data that is stored in the .gdb folder.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Move your&amp;nbsp;Trail_Data_A.shp, Trail_Data_A.dbf,&amp;nbsp;Trail_Data_A.shx,&amp;nbsp;Trail_Data_A.* files out of the&amp;nbsp;Trial_out.gdb folder to a normal folder.&lt;/LI&gt;&lt;LI&gt;If you want a file geodatabase feature class, use ArcGIS to export your shapefile to the database.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 09:15:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1131118#M63412</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2022-01-06T09:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1135384#M63543</link>
      <description>&lt;P&gt;I found a working output for the above mentioned question&lt;/P&gt;&lt;PRE&gt;inTable = r'H:\Python Projects\PycharmProjects\ArcPy\Test_Output\Trial_out.gdb\Trail_Data_A.shp'

func_1 = "'!AttArt_Ken!'.split('_')[0]"
field_1 = "ObjArt_Ken"

func_2 = "'!AttArt_Ken!'.split('_')[1]"
field_2 = "Wert"

arcpy.AddField_management(inTable, field_1, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_1, func_1, "PYTHON_9.3")

arcpy.AddField_management(inTable, field_2, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_2, func_2, "PYTHON_9.3")&lt;/PRE&gt;&lt;P&gt;But a problem still exists such that the output (After split function) is like |ObjArt_Ken|Wert| |:---|:---| |u"31001|1001"|&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.olansies.com/" target="_self"&gt;I&lt;/A&gt; still couldn't figure out a way to remove the unicode or the '"' symbol from the desired output&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 12:38:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1135384#M63543</guid>
      <dc:creator>MalikaCheema</dc:creator>
      <dc:date>2022-01-20T12:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the Calculate Field using ArcPy?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1135392#M63544</link>
      <description>&lt;P&gt;Seems like you saved the unicode symbol and the double quotes as actual text.&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# define a function that will convert 'u"1234_5678"' to '1234_5678'
# CalculateField needs it as string
code_block = """
def clean_up(text_value):
    if text_value.startswith('u"'):
        text_value = text_value[1:]  # remove unicode symbol
    return text_value.replace('"', '')  # remove double quotes
"""

func_1 = "clean_up(!AttArt_Ken!).split('_')[0]"  # without single quotes around the field name!
field_1 = "ObjArt_Ken"

func_2 = "clean_up(!AttArt_Ken!).split('_')[1]" # without single quotes around the field name!
field_2 = "Wert"

arcpy.AddField_management(inTable, field_1, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_1, func_1, "PYTHON_9.3", code_block)

arcpy.AddField_management(inTable, field_2, "TEXT".encode('utf-8'))
arcpy.CalculateField_management(inTable, field_2, func_2, "PYTHON_9.3", code_block)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Jan 2022 13:10:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-run-the-calculate-field-using-arcpy/m-p/1135392#M63544</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-20T13:10:40Z</dc:date>
    </item>
  </channel>
</rss>

