<?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: Error 000539: Invalid Field . Failed execution of (CalculateField) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124411#M63205</link>
    <description>&lt;P&gt;thank you for your answer, I already tried this solution, but it gives the following error :&lt;BR /&gt;arcpy.CalculateField_management("BATI", CHAMPS, RESULTA, "PYTHON")&lt;BR /&gt;File "c:\program files\arcgis\desktop10.5\arcpy\arcpy\management.py", line 3663, in CalculateField&lt;BR /&gt;raise e&lt;BR /&gt;ExecuteError: ERROR 000539: Field CHAMP1 invalid.&lt;BR /&gt;Failed to execute (CalculateField).&lt;/P&gt;</description>
    <pubDate>Thu, 09 Dec 2021 16:23:42 GMT</pubDate>
    <dc:creator>echlouchi</dc:creator>
    <dc:date>2021-12-09T16:23:42Z</dc:date>
    <item>
      <title>Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124306#M63192</link>
      <description>&lt;PRE&gt;&lt;SPAN&gt;Hello! &lt;BR /&gt;I'm sure this is a simple issue, but it's stumped me.&lt;BR /&gt;I'm new to python, please help me.&lt;BR /&gt;I have calculated two equations from two fields without any problem.&lt;BR /&gt;When I calculate the third equation using the results of the first,&lt;BR /&gt;an error occurs: Error 000539: Invalid Field . Failed to execute (CalculateField).&lt;BR /&gt;I don't know what to do in this case.&lt;BR /&gt;here's my code.&lt;BR /&gt;--------------------------------------------------------------------------&lt;BR /&gt;import &lt;/SPAN&gt;arcpy&lt;BR /&gt;&lt;SPAN&gt;# Set environment settings&lt;BR /&gt;&lt;/SPAN&gt;arcpy.env.workspace = arcpy.GetParameterAsText(&lt;SPAN&gt;0&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;# arcpy.env.workspace = "D:\DocEnergy\DATA\BATIMENTS.gdb"&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;# ----------------------------------------&lt;BR /&gt;&lt;/SPAN&gt;DDD = arcpy.GetParameterAsText(&lt;SPAN&gt;1&lt;/SPAN&gt;).replace(&lt;SPAN&gt;','&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'.'&lt;/SPAN&gt;)&lt;BR /&gt;DDDF = &lt;SPAN&gt;float&lt;/SPAN&gt;(DDD)&lt;BR /&gt;&lt;BR /&gt;fc = arcpy.GetParameterAsText(&lt;SPAN&gt;2&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# fields&lt;/SPAN&gt;&lt;BR /&gt;CHAMP1 = arcpy.GetParameterAsText(&lt;SPAN&gt;3&lt;/SPAN&gt;)&lt;BR /&gt;CHAMP2 = arcpy.GetParameterAsText(&lt;SPAN&gt;4&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# --------------------------------------------------&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;# EAUATION ET FORMULES&lt;BR /&gt;&lt;/SPAN&gt;RESULTA1 = &lt;SPAN&gt;"!{0}!*!{1}!+{2}"&lt;/SPAN&gt;.format(CHAMP1&lt;SPAN&gt;, &lt;/SPAN&gt;CHAMP2&lt;SPAN&gt;, &lt;/SPAN&gt;DDDF)&lt;BR /&gt;RESULTA2 = &lt;SPAN&gt;"!{0}!*!{1}!-{2}"&lt;/SPAN&gt;.format(CHAMP1&lt;SPAN&gt;, &lt;/SPAN&gt;CHAMP2&lt;SPAN&gt;, &lt;/SPAN&gt;DDDF)&lt;BR /&gt;&lt;BR /&gt;# how can I calculate this equation from the two equations RASULTA1 AND RESULTA2 ?&lt;BR /&gt;RESULTA = &lt;SPAN&gt;"!{0}!*!{1}!"&lt;/SPAN&gt;.format(RESULTA1&lt;SPAN&gt;, &lt;/SPAN&gt;RESULTA2) &lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Input the name of the field to be created&lt;BR /&gt;&lt;/SPAN&gt;CHAMPS = arcpy.GetParameterAsText(&lt;SPAN&gt;5&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Add field&lt;BR /&gt;&lt;/SPAN&gt;arcpy.AddField_management(&lt;SPAN&gt;"BATI"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;CHAMPS&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"float"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;20&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;10&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# CalculateField&lt;BR /&gt;&lt;/SPAN&gt;arcpy.CalculateField_management(&lt;SPAN&gt;"BATI"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;CHAMPS&lt;SPAN&gt;, &lt;/SPAN&gt;RESULTA&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"PYTHON"&lt;/SPAN&gt;)&lt;BR /&gt;-------------------------------------------------------------------&lt;BR /&gt;thank you !!&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 14:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124306#M63192</guid>
      <dc:creator>echlouchi</dc:creator>
      <dc:date>2021-12-09T14:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124311#M63193</link>
      <description>&lt;P&gt;RESULTA1 = "!{0}!*!{1}!+{2}".format(CHAMP1, CHAMP2, DDDF)&lt;BR /&gt;RESULTA2 = "!{0}!*!{1}!-{2}".format(CHAMP1, CHAMP2, DDDF)&lt;/P&gt;&lt;P&gt;# how can I calculate this equation from the two equations RASULTA1 AND RESULTA2 ?&lt;BR /&gt;RESULTA = "!{0}!*!{1}!".format(RESULTA1, RESULTA2)&lt;/P&gt;&lt;P&gt;RESULTA1 and RESULTA2 are text&lt;/P&gt;&lt;P&gt;hence&lt;/P&gt;&lt;P&gt;RESULTA = "!{0}!*!{1}!".format(float(RESULTA1), float(RESULTA2))&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 14:12:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124311#M63193</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-09T14:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124316#M63194</link>
      <description>&lt;P&gt;thank you for your feedback !&lt;/P&gt;&lt;P&gt;I have tested your proposal, but it gives an error:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;RESULTA = "!{0}!*!{1}!".format(float(RESULTA1), float(RESULTA2))&lt;BR /&gt;ValueError: could not convert string to float: !U_r1!*!U_r2!+10.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 14:23:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124316#M63194</guid>
      <dc:creator>echlouchi</dc:creator>
      <dc:date>2021-12-09T14:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124349#M63197</link>
      <description>&lt;LI-CODE lang="python"&gt;RESULTA1 = "!{0}!*!{1}!+{2}".format(CHAMP1, CHAMP2, DDDF)
RESULTA2 = "!{0}!*!{1}!-{2}".format(CHAMP1, CHAMP2, DDDF)
#RESULTA1 = '!CHAMP1!*!CHAMP2!+9.4'
#RESULTA2 = '!CHAMP1!*!CHAMP2!-9.4'

RESULTA = "({0}) * ({1})".format(RESULTA1, RESULTA2)
#'(!CHAMP1!*!CHAMP2!+9.4) * (!CHAMP1!*!CHAMP2!-9.4)'&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 15:23:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124349#M63197</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-12-09T15:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124403#M63202</link>
      <description>&lt;P&gt;or simply dump the extra string stuff&lt;/P&gt;&lt;LI-CODE lang="python"&gt;RESULTA1 = "5"
RESULTA2 = "4"
# -- one method
RESULTA = float(f"{RESULTA1}") * float(f"{RESULTA2}")
# -- even simpler
RESULTA = float(RESULTA1) * float(RESULTA2)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:14:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124403#M63202</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-09T16:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124405#M63203</link>
      <description>&lt;P&gt;t&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:24:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124405#M63203</guid>
      <dc:creator>echlouchi</dc:creator>
      <dc:date>2021-12-09T16:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124411#M63205</link>
      <description>&lt;P&gt;thank you for your answer, I already tried this solution, but it gives the following error :&lt;BR /&gt;arcpy.CalculateField_management("BATI", CHAMPS, RESULTA, "PYTHON")&lt;BR /&gt;File "c:\program files\arcgis\desktop10.5\arcpy\arcpy\management.py", line 3663, in CalculateField&lt;BR /&gt;raise e&lt;BR /&gt;ExecuteError: ERROR 000539: Field CHAMP1 invalid.&lt;BR /&gt;Failed to execute (CalculateField).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:23:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124411#M63205</guid>
      <dc:creator>echlouchi</dc:creator>
      <dc:date>2021-12-09T16:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124428#M63206</link>
      <description>&lt;P&gt;I don't know if I understood your solution correctly, I tested&amp;nbsp;but it gives an error:&lt;/P&gt;&lt;PRE&gt;RESULTA = float(RESULTA1) * float(RESULTA2)&lt;/PRE&gt;&lt;P&gt;but it gives an error: File "D:\DocEnergy - copy+++++\SCRIPTE FINALLL 10-12-2021.py", line 27, in &amp;lt;module&amp;gt;&lt;BR /&gt;RESULTA = float(RESULTA1) * float(RESULTA2)&lt;BR /&gt;ValueError: could not convert string to float&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 16:39:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124428#M63206</guid>
      <dc:creator>echlouchi</dc:creator>
      <dc:date>2021-12-09T16:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124469#M63208</link>
      <description>&lt;P&gt;Calculate field... missed that&lt;/P&gt;&lt;LI-CODE lang="python"&gt;code_block = """
def calc(f0, f1, f2):
    a = (f0 * f1) + f2
    b = (f0 * f1) - f2
    return a * b"""&lt;/LI-CODE&gt;&lt;P&gt;expression&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ex = "calc(!CHAMP1!, !CHAMP2!, !DDDF!)"&lt;/LI-CODE&gt;&lt;P&gt;arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3",codeblock)&lt;/P&gt;&lt;P&gt;hence&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management("BATI", "CHAMPS", expression=ex,&amp;nbsp;"PYTHON3", codeblock=code_block)&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 17:49:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124469#M63208</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-09T17:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124603#M63217</link>
      <description>&lt;P&gt;Thank you &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;DanPatterson&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;, your solution worked well, just need to add to the expression :&lt;BR /&gt;expression = &lt;STRONG&gt;"calc (!{0}!, !{1}!, {2})".format(CHAMP1, CHAMP2, DDDF )&lt;/STRONG&gt;&lt;BR /&gt;Thank you !!!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 21:18:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124603#M63217</guid>
      <dc:creator>khalidechlouchi</dc:creator>
      <dc:date>2021-12-09T21:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Error 000539: Invalid Field . Failed execution of (CalculateField)</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124614#M63219</link>
      <description>&lt;P&gt;glad it worked out&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 21:24:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-invalid-field-failed-execution-of/m-p/1124614#M63219</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-12-09T21:24:05Z</dc:date>
    </item>
  </channel>
</rss>

