<?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 Merging Strings for a new key in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131765#M26092</link>
    <description>&lt;P&gt;So I am updating a working in 10.8.1; before we migrate to Pro. I have a couple existing values (quarter and year_2dig) that we use. I an wanting to do something like this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;valuePrefix = &lt;/SPAN&gt;&lt;SPAN&gt;"Q"&lt;/SPAN&gt;&lt;SPAN&gt; + &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;(quarter) + &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;(year_2dig) + &lt;/SPAN&gt;&lt;SPAN&gt;"_"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Then&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.CalculateField_management(loccode_fc, &lt;/SPAN&gt;&lt;SPAN&gt;"QRTR_KEY"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'"valuePrefix !OBJECTID!"'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"PYTHON"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;So I would have a new unique value that says Q122_1 ... etc for each row&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But instead I get "colPrefix + 1" as the value...&amp;nbsp; Ideas?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sat, 08 Jan 2022 00:36:37 GMT</pubDate>
    <dc:creator>DEWright_CA</dc:creator>
    <dc:date>2022-01-08T00:36:37Z</dc:date>
    <item>
      <title>Merging Strings for a new key</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131765#M26092</link>
      <description>&lt;P&gt;So I am updating a working in 10.8.1; before we migrate to Pro. I have a couple existing values (quarter and year_2dig) that we use. I an wanting to do something like this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;valuePrefix = &lt;/SPAN&gt;&lt;SPAN&gt;"Q"&lt;/SPAN&gt;&lt;SPAN&gt; + &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;(quarter) + &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;(year_2dig) + &lt;/SPAN&gt;&lt;SPAN&gt;"_"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Then&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy.CalculateField_management(loccode_fc, &lt;/SPAN&gt;&lt;SPAN&gt;"QRTR_KEY"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'"valuePrefix !OBJECTID!"'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"PYTHON"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;""&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;So I would have a new unique value that says Q122_1 ... etc for each row&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But instead I get "colPrefix + 1" as the value...&amp;nbsp; Ideas?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 08 Jan 2022 00:36:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131765#M26092</guid>
      <dc:creator>DEWright_CA</dc:creator>
      <dc:date>2022-01-08T00:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Strings for a new key</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131895#M26093</link>
      <description>&lt;P&gt;It looks like you are erroneously embedding your string&amp;nbsp;&lt;EM&gt;within&amp;nbsp;&lt;/EM&gt;the string and using the wrong python parser,&lt;/P&gt;&lt;P&gt;Your code should be:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;valuePrefix = "Q" + str(quarter) + str(year_2dig) + "_"
arcpy.CalculateField_management(loccode_fc, "QRTR_KEY", '"' + valuePrefix + "!OBJECTID!" + '"',"PYTHON_9.3","")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jan 2022 18:57:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131895#M26093</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-01-09T18:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Strings for a new key</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131951#M26095</link>
      <description>&lt;LI-CODE lang="python"&gt;# CalculateField can be a little hard to understand, because you have to pass
# a string that evaluates to a correct Python expression. Biggest pitfall that
# I see on this forum is concatenating strings, because people get mixed up
# with the quotation marks of their expression and the quotation marks _around_
# the expression (that make it into a string).

# It's not clear from your question where quarter and year_2dig come from,
# chose the correct expression from below. Alo, note the double quotes inside
# the expression and the single quotes to turn the expression into a string.

# if quarter and year_2dig are fields in the table, this will result in
# '"Q{}{}_{}".format(!QUARTER!, !YEAR_2DIG!, !OBJECTID!)'
expression = '"Q{}{}_{}".format(!QUARTER!, !YEAR_2DIG!, !OBJECTID!)'

# if quarter and year_2dig are python variables, this will result in
# '"Q122_{}".format(!OBJECTID!)'
expression = '"Q{}{}_'.format(quarter, year_2dig) + '{}".format(!OBJECTID!)'

arcpy.CalculateField_management(loccode_fc, "QRTR_KEY", expression, "PYTHON_9.3", "")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jan 2022 08:47:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131951#M26095</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-10T08:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Strings for a new key</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131952#M26096</link>
      <description>&lt;LI-CODE lang="python"&gt;valuePrefix = "Q" + str(1) + str(22) + "_"
'"' + valuePrefix + "!OBJECTID!" + '"'
# '"Q122_!OBJECTID!"'&lt;/LI-CODE&gt;&lt;P&gt;That doesn't seem right.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'"' + valuePrefix + '"' + " + str(!OBJECTID!)"
# '"Q122_" + str(!OBJECTID!)'&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 10 Jan 2022 08:53:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1131952#M26096</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-01-10T08:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Strings for a new key</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1132524#M26102</link>
      <description>&lt;P&gt;Perfect; so I was close; I thought it was just a mixture of the right set of quotes and double-quotes just was running out of places to try.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 17:29:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/merging-strings-for-a-new-key/m-p/1132524#M26102</guid>
      <dc:creator>DEWright_CA</dc:creator>
      <dc:date>2022-01-11T17:29:04Z</dc:date>
    </item>
  </channel>
</rss>

