<?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: Add/Calculate Field within a python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722770#M55971</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!!! It works like a charm now!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just for future reference, can you point me the ESRI web help for the field calculator used in python script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For instance, I never saw this in any help document before: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14155835323054636 jive_text_macro" jivemacro_uid="_14155835323054636"&gt;
&lt;P&gt;&lt;SPAN&gt;"'{0}'".format(arcpy.GetParameterAsText(3)) &lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Mar 2013 15:37:12 GMT</pubDate>
    <dc:creator>AlexGole1</dc:creator>
    <dc:date>2013-03-15T15:37:12Z</dc:date>
    <item>
      <title>Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722764#M55965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to build a tool in python that selects by location, copy to new feature class, add a field to the new feature class, and calculate the field that was just added in the script. The first part of the script works well, however it stops working when adding field/calculating field. I am not quite sure why... &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The error is: ERROR 000728 on CalculateField: Field Does not exist. In my script I specifically added a python line to add a line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What lines in this script are wrong (adding field or calculate field, both?)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alex&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: The calculate field first purpose was to do the following: the field "Update" = "arcpy.GetParameter(3)" (the text will be entered by the tool user.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 18:52:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722764#M55965</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2013-03-14T18:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722765#M55966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the issue is with your Expression variable. Here is what you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;UpdatedField = "Update"
Expression = (" = " + "'" + arcpy.GetParameter(3) + "'")
arcpy.CalculateField_management(Selected_cnddb_point, UpdatedField, Expression, "PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your user entered parameter was "hello", the expression would be: ='hello' and not: "Update" = 'hello'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think your Expression variable should actually be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Expression = '"Update" = ' + "'" + arcpy.GetParameter(3) + "'"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:55:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722765#M55966</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2021-12-12T06:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722766#M55967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your quick answer. I just tried your line. The positive thing is that i get a different error. The error is: "cannot concatenate 'str' and 'geoprocessing value object' objects".&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not sure how else I could possibly calculate this field...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 20:37:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722766#M55967</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2013-03-14T20:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722767#M55968</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think your Expression variable should actually be:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Expression = '"Update" = ' + "'" + arcpy.GetParameter(3) + "'"&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or better yet, use Python string formatting - easier to get the syntax right. The expression just has to be the part that you would have typed into the Calculate Field dialog -- "Update = " is handled by putting your field UpdatedField in the second argument.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The error is: "cannot concatenate 'str' and 'geoprocessing value object' objects".&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also recommend using arcpy.GetParameterAsText unless you have a special reason for needing to use GetParameter (value tables etc).&amp;nbsp; The text representation is usually much easier to work with, as&amp;nbsp; you have discovered.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I moved the message first because it makes sense to say what you're about to do before you do it...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Add Field
arcpy.AddMessage("Adding Updated Field...") 
arcpy.AddField_management(Selected_cnddb_point, UpdatedField, "TEXT", "", "", "50","", "NULLABLE")


#Calculate Field
arcpy.AddMessage("Calculating Updated Field...")
Expression = "'{0}'".format(arcpy.GetParameterAsText(3)) # single quoted string literal
arcpy.CalculateField_management(Selected_cnddb_point, UpdatedField, Expression, "PYTHON")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:55:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722767#M55968</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T06:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722768#M55969</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you! It seems like the script is running better now. However, I still come back to my first error. ERROR 00728: Field Update does not exist within table... I am not sure why because the two lines before calculating the field were specifically written to create this field...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 20:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722768#M55969</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2013-03-14T20:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722769#M55970</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you! It seems like the script is running better now. However, I still come back to my first error. ERROR 00728: Field Update does not exist within table... I am not sure why because the two lines before calculating the field were specifically written to create this field...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My guess is the field name "Update" was not legal for that workspace/table type, so the field name got saved as something legal like&amp;nbsp; "UPDATE_". (UPDATE is a reserved word in SQL.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try to add a field to a fGDB table with this name interactively, I get a warning:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;WARNING 000304: Renamed field Update to Update_ Adding Update_ to sampcells_RotateFeatures...&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See the help for &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002z00000020000000" rel="nofollow" target="_blank"&gt;arcpy.ValidateFieldName&lt;/A&gt;&lt;SPAN&gt; for more details on how to deal with that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 22:31:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722769#M55970</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-14T22:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722770#M55971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!!! It works like a charm now!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Just for future reference, can you point me the ESRI web help for the field calculator used in python script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For instance, I never saw this in any help document before: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14155835323054636 jive_text_macro" jivemacro_uid="_14155835323054636"&gt;
&lt;P&gt;&lt;SPAN&gt;"'{0}'".format(arcpy.GetParameterAsText(3)) &lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 15:37:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722770#M55971</guid>
      <dc:creator>AlexGole1</dc:creator>
      <dc:date>2013-03-15T15:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add/Calculate Field within a python script</title>
      <link>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722771#M55972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're welcome!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you point me the ESRI web help for the field calculator used in python script.&lt;BR /&gt;For instance, I never saw this in any help document before: &lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;Expression = "'{0}'".format(arcpy.GetParameterAsText(3))&lt;/SPAN&gt; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a Python thing. Although there are three main ways to do string formatting in Python, the format() function is current way to do it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2/tutorial/inputoutput.html#fancier-output-formatting"&gt;Python Tutorial: 7.1. Fancier Output Formatting&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2013 17:49:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-calculate-field-within-a-python-script/m-p/722771#M55972</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-15T17:49:45Z</dc:date>
    </item>
  </channel>
</rss>

