<?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: Python: Calculate field to not type parentheses for text in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260665#M26728</link>
    <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;can you refer to specific lines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Feb 2023 21:21:37 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2023-02-22T21:21:37Z</dc:date>
    <item>
      <title>Python: Calculate field to not type parentheses for text</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260645#M26727</link>
      <description>&lt;P&gt;I have a script and I want to let user type in a value (text).&amp;nbsp; My problem is the user has to put " " for the value they want for any of the newly added fields.&amp;nbsp; ex: "virginia" works virginia does not work.&amp;nbsp; How can I get the toolbox to work without the user typing&amp;nbsp; " " and just type the value.&amp;nbsp; I have looked at the properties parameters of the script and have the data type set to String or Any Value but nothing works.&amp;nbsp; I could find anything online to fix this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;inMosaic = arcpy.GetParameterAsText(0)&lt;/P&gt;&lt;P&gt;yearfield = arcpy.GetParameterAsText(1)&lt;BR /&gt;installfield = arcpy.GetParameterAsText(2)&lt;BR /&gt;sitefield = arcpy.GetParameterAsText(3)&lt;BR /&gt;groupnamefield = arcpy.GetParameterAsText(4)&lt;BR /&gt;productnamefield = arcpy.GetParameterAsText(5)&lt;/P&gt;&lt;P&gt;fieldNames = ["YEAR", "INST_ABBR", "SITE_ABBR"]&lt;BR /&gt;aliasNames = ["Year", "Installation Abbreviation", "Site Abbreviation"]&lt;/P&gt;&lt;P&gt;fieldsExisting = {f.name: f.type for f in arcpy.ListFields(inMosaic)}&lt;BR /&gt;count = 0&lt;BR /&gt;for fName in fieldNames:&lt;BR /&gt;if fName not in fieldsExisting.keys(): # Check if field is not already present in the Mosaic Dataset attribute table&lt;BR /&gt;arcpy.AddField_management(inMosaic, fName, "TEXT", field_alias=aliasNames[count], field_length=10) # If not, add field&lt;BR /&gt;arcpy.AddMessage("{0} field has been added to Mosaic Dataset!".format(fName))&lt;BR /&gt;count += 1 # Increase counter for each loop. This is necessary for iterating through the aliasNames list&lt;/P&gt;&lt;P&gt;arcpy.management.CalculateField(inMosaic,"YEAR", yearfield)&lt;BR /&gt;arcpy.management.CalculateField(inMosaic,"INST_ABBR", installfield)&lt;BR /&gt;arcpy.management.CalculateField(inMosaic,"SITE_ABBR", sitefield)&lt;BR /&gt;arcpy.management.CalculateField(inMosaic,"GroupName", groupnamefield)&lt;BR /&gt;arcpy.management.CalculateField(inMosaic,"ProductName", productnamefield)&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 20:48:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260645#M26727</guid>
      <dc:creator>EricS</dc:creator>
      <dc:date>2023-02-22T20:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Calculate field to not type parentheses for text</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260665#M26728</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;can you refer to specific lines?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 21:21:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260665#M26728</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-02-22T21:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Calculate field to not type parentheses for text</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260735#M26729</link>
      <description>&lt;P&gt;Any of the calculate field code:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.management.CalculateField(inMosaic,"YEAR", yearfield)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have yearfield = getparameterastext and the script properties has it set to string&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 00:52:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260735#M26729</guid>
      <dc:creator>EricS</dc:creator>
      <dc:date>2023-02-23T00:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Calculate field to not type parentheses for text</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260802#M26730</link>
      <description>&lt;P&gt;Here's the problem:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(inTable, "TextField", "some text")

# the tool will try to evaluate the expression. Internally, it will try to run this:
def expression():
    return some text

# this of course fails, because it's not valid syntax, and because it evaluates _some_ and _text_ as variales, and they aren't defined

# to fix that, you have to correctly escape your strings:
arcpy.management.CalculateField(inTable, "TextField", "'some text'")

def expression():
    return 'some text'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's how you can fix it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(inMosaic, "YEAR", "'{}'".format(yearfield))&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Feb 2023 08:37:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260802#M26730</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-02-23T08:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Calculate field to not type parentheses for text</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260916#M26731</link>
      <description>&lt;P&gt;Thank you for your help!&amp;nbsp; It worked perfectly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:13:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-calculate-field-to-not-type-parentheses-for/m-p/1260916#M26731</guid>
      <dc:creator>EricS</dc:creator>
      <dc:date>2023-02-23T15:13:33Z</dc:date>
    </item>
  </channel>
</rss>

