<?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 CalculateField_management problem setting string data in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculatefield-management-problem-setting-string/m-p/190061#M14595</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am reading in ExtendedData/Data from a KML to add additional data fields/data to a FeatureClass using ArcPRO 2.0.1. I am using a hashmap to store the key-value Data/value pairs. To set the data, I am making calls with arcpy.CalculateField_management. When I grab the data, I am prepending and appending double quotes " (ie. hashData = '"' + hashKMLData[hashKey] + "'" and thus making the call:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(myfeature, hashKey, hashData)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some of the data are just numbers and ARE stored correctly. However, Strings/String mixed with numbers&amp;nbsp;and List data (enclosed in '[ ]' brackets) are problematic. Only the first character is getting set in the corresponding fields. I have tried to coerce the data types&amp;nbsp;based on the field types (ie. str(hashData)). I have even tried setting all fields to "Text" but still have troubles with string data (ie. "I say foo a lot" gets stored as "I" in our SDE).&amp;nbsp;It's as though setting these values is truncated to the first character.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm at a loss - any help is much appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Feb 2019 21:30:17 GMT</pubDate>
    <dc:creator>RobertHarvey</dc:creator>
    <dc:date>2019-02-21T21:30:17Z</dc:date>
    <item>
      <title>CalculateField_management problem setting string data</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-problem-setting-string/m-p/190061#M14595</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am reading in ExtendedData/Data from a KML to add additional data fields/data to a FeatureClass using ArcPRO 2.0.1. I am using a hashmap to store the key-value Data/value pairs. To set the data, I am making calls with arcpy.CalculateField_management. When I grab the data, I am prepending and appending double quotes " (ie. hashData = '"' + hashKMLData[hashKey] + "'" and thus making the call:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(myfeature, hashKey, hashData)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some of the data are just numbers and ARE stored correctly. However, Strings/String mixed with numbers&amp;nbsp;and List data (enclosed in '[ ]' brackets) are problematic. Only the first character is getting set in the corresponding fields. I have tried to coerce the data types&amp;nbsp;based on the field types (ie. str(hashData)). I have even tried setting all fields to "Text" but still have troubles with string data (ie. "I say foo a lot" gets stored as "I" in our SDE).&amp;nbsp;It's as though setting these values is truncated to the first character.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm at a loss - any help is much appreciated.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Feb 2019 21:30:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-problem-setting-string/m-p/190061#M14595</guid>
      <dc:creator>RobertHarvey</dc:creator>
      <dc:date>2019-02-21T21:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField_management problem setting string data</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-management-problem-setting-string/m-p/190062#M14596</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In general it's much easier to use Python string formatting:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# Instead of:# hashData = '"' + hashKMLData[hashKey] + "'"  &lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# arcpy.CalculateField_management(myfeature, hashKey, hashData)&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# try this:&lt;/SPAN&gt;
hashData &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'"{}"'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hashKMLData&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;hashkey&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#debug using repr to see what's REALLY there&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;repr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hashkey&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;repr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hashKMLData&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;hashkey&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;repr&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hashData&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CalculateField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;myfeature&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; hashKey&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; hashData&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I think the issue is your data are not ready to be stringed, like there are embedded lists which you seem to be saying here. This means you need to do some additional debugging and coding, but it's a LOT easier to do it using string formatting instead of concatenating&amp;nbsp;string with +.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Playing with parsing your data at a python prompt &amp;gt;&amp;gt;&amp;gt; can be often be valuable when figuring out strategies to handle your data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keep in mind that repr(hashData)&amp;nbsp;should&amp;nbsp;look like this when passed to Calculate Field as a calculate expression:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;r&lt;SPAN class="string token"&gt;"'My favorite string'"&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# strings, with any embedded quotes escaped&lt;/SPAN&gt;
r&lt;SPAN class="string token"&gt;"999.0"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;or&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;999.0&lt;/SPAN&gt;       &lt;SPAN class="comment token"&gt;# numbers‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:34:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-management-problem-setting-string/m-p/190062#M14596</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T09:34:12Z</dc:date>
    </item>
  </channel>
</rss>

