<?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 Concatenating Strings with Field Calculator and Python - dealing with NULLS in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142702#M11107</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have some addressing data that I would like to update and one of the tasks is to concatenate a new full street address field [ADDR1] by combining several of the component fields.&amp;nbsp; I know how to do this in VBScript, but figured this would be a good example to work out in Python, as I don't use Python often and have alot to learn.&amp;nbsp; My programming background is FORTRAN and BASIC, and in the years since those were popular hack and slash adapting code for AML/Avenue/VBA/VB.Net - so assume I know little about Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is desired (psuedo-logic):&lt;/P&gt;&lt;P&gt;ADDR1 = STRNUM + STRNUMSUF + STRPREDIR + STRNAME + STRTYPE + STRSUFDIR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using ArcGIS 10.2.1 and the data shown here is test data in a File Geodatabase feature class. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After poking around various Help articles, it appears that in Python the .format method in would work.&amp;nbsp; However, when I run it in Field Calculator the result looks good except "None" gets concatenated as text if the original field value was NULL (this issue doesn't come up with VBScript).&amp;nbsp; I'd like any values of NULL to instead just be blank - i.e. ignore them entirely.&amp;nbsp; For example, for the first record the desired outcome in ADDR1 is "224 D N CHURCH ST" not "224 D N CHURCH ST None".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Concatenation Python NULLS become None.png" class="image-1 jive-image" src="/legacyfs/online/139627_Concatenation Python NULLS become None.png" style="width: 620px; height: 311px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the Python articles I found mentions the NULL issue:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Dealing with Null Values.jpg" class="image-2 jive-image" src="/legacyfs/online/139649_Dealing with Null Values.jpg" style="width: 620px; height: 153px;" /&gt;&lt;/P&gt;&lt;P&gt;Source:&amp;nbsp; &lt;A href="http://blogs.esri.com/esri/arcgis/2010/08/30/concatenate/" title="http://blogs.esri.com/esri/arcgis/2010/08/30/concatenate/"&gt;Concatenating field values using Calculate Field | ArcGIS Blog&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a different way to do the concatenation in Python to achieve the desired outcome?&amp;nbsp; I'm trying to wrap my head around how Python approaches this, particularly in regards to using it in ArcMap in Field Calculator.&amp;nbsp; &lt;/P&gt;&lt;UL&gt;&lt;LI&gt; I noticed some articles suggested &lt;EM&gt;casting&lt;/EM&gt; all the fields to string to resolve the NULLS.&amp;nbsp; However, I haven't had any luck adding in str() in with the fields in the &lt;EM&gt;format&lt;/EM&gt; statement shown.&amp;nbsp; It would just error out.&amp;nbsp; Would this need to be a separate line to do the &lt;EM&gt;casting&lt;/EM&gt;?&lt;/LI&gt;&lt;LI&gt; Would a better approach be to use the Codeblock to run some sort of process to convert NULLS to blank before running the &lt;EM&gt;format&lt;/EM&gt; method?&amp;nbsp; For example, adapt a process similar to this?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;IMG alt="FixNull.jpg" class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/139650_FixNull.jpg" style="width: 620px; height: 279px;" /&gt;&lt;/P&gt;&lt;P&gt;Source:&amp;nbsp; &lt;A href="http://gis.stackexchange.com/questions/81143/calculate-field-tool-to-calculate-on-null-fields?lq=1" title="http://gis.stackexchange.com/questions/81143/calculate-field-tool-to-calculate-on-null-fields?lq=1"&gt;arcgis desktop - Calculate Field tool to calculate on null fields - Geographic Information Systems Stack Exchange&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly, can you recommend a good guide for beginners that explains how to use Python for these sort of issues?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Nov 2015 19:08:49 GMT</pubDate>
    <dc:creator>ChrisDonohue__GISP</dc:creator>
    <dc:date>2015-11-06T19:08:49Z</dc:date>
    <item>
      <title>Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142702#M11107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have some addressing data that I would like to update and one of the tasks is to concatenate a new full street address field [ADDR1] by combining several of the component fields.&amp;nbsp; I know how to do this in VBScript, but figured this would be a good example to work out in Python, as I don't use Python often and have alot to learn.&amp;nbsp; My programming background is FORTRAN and BASIC, and in the years since those were popular hack and slash adapting code for AML/Avenue/VBA/VB.Net - so assume I know little about Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is desired (psuedo-logic):&lt;/P&gt;&lt;P&gt;ADDR1 = STRNUM + STRNUMSUF + STRPREDIR + STRNAME + STRTYPE + STRSUFDIR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using ArcGIS 10.2.1 and the data shown here is test data in a File Geodatabase feature class. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After poking around various Help articles, it appears that in Python the .format method in would work.&amp;nbsp; However, when I run it in Field Calculator the result looks good except "None" gets concatenated as text if the original field value was NULL (this issue doesn't come up with VBScript).&amp;nbsp; I'd like any values of NULL to instead just be blank - i.e. ignore them entirely.&amp;nbsp; For example, for the first record the desired outcome in ADDR1 is "224 D N CHURCH ST" not "224 D N CHURCH ST None".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Concatenation Python NULLS become None.png" class="image-1 jive-image" src="/legacyfs/online/139627_Concatenation Python NULLS become None.png" style="width: 620px; height: 311px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the Python articles I found mentions the NULL issue:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Dealing with Null Values.jpg" class="image-2 jive-image" src="/legacyfs/online/139649_Dealing with Null Values.jpg" style="width: 620px; height: 153px;" /&gt;&lt;/P&gt;&lt;P&gt;Source:&amp;nbsp; &lt;A href="http://blogs.esri.com/esri/arcgis/2010/08/30/concatenate/" title="http://blogs.esri.com/esri/arcgis/2010/08/30/concatenate/"&gt;Concatenating field values using Calculate Field | ArcGIS Blog&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a different way to do the concatenation in Python to achieve the desired outcome?&amp;nbsp; I'm trying to wrap my head around how Python approaches this, particularly in regards to using it in ArcMap in Field Calculator.&amp;nbsp; &lt;/P&gt;&lt;UL&gt;&lt;LI&gt; I noticed some articles suggested &lt;EM&gt;casting&lt;/EM&gt; all the fields to string to resolve the NULLS.&amp;nbsp; However, I haven't had any luck adding in str() in with the fields in the &lt;EM&gt;format&lt;/EM&gt; statement shown.&amp;nbsp; It would just error out.&amp;nbsp; Would this need to be a separate line to do the &lt;EM&gt;casting&lt;/EM&gt;?&lt;/LI&gt;&lt;LI&gt; Would a better approach be to use the Codeblock to run some sort of process to convert NULLS to blank before running the &lt;EM&gt;format&lt;/EM&gt; method?&amp;nbsp; For example, adapt a process similar to this?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;IMG alt="FixNull.jpg" class="image-3 jive-image" src="https://community.esri.com/legacyfs/online/139650_FixNull.jpg" style="width: 620px; height: 279px;" /&gt;&lt;/P&gt;&lt;P&gt;Source:&amp;nbsp; &lt;A href="http://gis.stackexchange.com/questions/81143/calculate-field-tool-to-calculate-on-null-fields?lq=1" title="http://gis.stackexchange.com/questions/81143/calculate-field-tool-to-calculate-on-null-fields?lq=1"&gt;arcgis desktop - Calculate Field tool to calculate on null fields - Geographic Information Systems Stack Exchange&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly, can you recommend a good guide for beginners that explains how to use Python for these sort of issues?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 19:08:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142702#M11107</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T19:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142703#M11108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't have nulls in my fields, but you can glean some ideas from the options available below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = 12345
&amp;gt;&amp;gt;&amp;gt; b = None
&amp;gt;&amp;gt;&amp;gt; c = "some text"
&amp;gt;&amp;gt;&amp;gt; d = ""
&amp;gt;&amp;gt;&amp;gt; e = "more"
&amp;gt;&amp;gt;&amp;gt; frmt = "{} {} {} {}".format(a,b,c,d,e)
&amp;gt;&amp;gt;&amp;gt; frmt2 = "{!s:} {!s:} {!s:} {!s:}".format(a,b,c,d,e)
&amp;gt;&amp;gt;&amp;gt; frmt3 = "{!r:} {!r:} {!r:} {!r:}".format(a,b,c,d,e)
&amp;gt;&amp;gt;&amp;gt; fld = " ".join([str(i) for i in [a,b,c,d,e] if i])
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; frmt
'12345 None some text '
&amp;gt;&amp;gt;&amp;gt; frmt2
'12345 None some text '
&amp;gt;&amp;gt;&amp;gt; frmt3
"12345 None 'some text' ''"
&amp;gt;&amp;gt;&amp;gt; fld
'12345 some text more'
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;note the last option is the only one that deals with None explicitly, so if your null values are equivalent to Python None, then this should work.&lt;/P&gt;&lt;P&gt;PS&amp;nbsp; you might have to do the string trimming thing is to get rid of preceeding or following spaces&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:51:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142703#M11108</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T07:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142704#M11109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured out how to make tables with nulls...not useful for me, but if you have them, here is an example&lt;/P&gt;&lt;P&gt;Field calculator expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" ".join([str(i) for i in [ !prefix_txt!, !number_int!, !main_txt!, !numb_dble!] if i])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The operative part is &lt;STRONG&gt; if i&lt;/STRONG&gt;&amp;nbsp; ])&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="139779" alt="table_nulls.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/139779_table_nulls.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:08:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142704#M11109</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-06T21:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142705#M11110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;The operative part is &lt;/SPAN&gt;&lt;SPAN style="font-weight: bold; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;if i&lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;In short:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if i: # checks if i 'exists'
&amp;nbsp; do something&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:51:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142705#M11110</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T07:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142706#M11111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It can also be interpreted as if i IS not just exists. I posted a blog on nothingness a while ago &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:30:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142706#M11111</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-06T21:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142707#M11112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan, that works.&amp;nbsp; I'm going to play with it a bit to try to get a better handle on it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was puzzled by the space " " in front of the join - I realized it was a separator to keep all the text from running into each other in the combined string but was worried it would add a space in front of the result, but it does not.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The "If i" is interesting.&amp;nbsp; Sort of like For-Next in other languages. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wonder why the .join method treats Nulls differently than the .format method does....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142707#M11112</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T21:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142708#M11113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, so that is why the result was different. &lt;STRONG&gt;&lt;EM&gt; If i&lt;/EM&gt;&lt;/STRONG&gt; sees Null as non-existing, so no join (and therefore no substitution text of 'None').&amp;nbsp; Makes sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:44:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142708#M11113</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T21:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142709#M11114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can't find your nothing post in your prolific blog. How does &lt;EM&gt;IS&lt;/EM&gt; differ from &lt;EM&gt;EXISTS&lt;/EM&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:47:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142709#M11114</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-06T21:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142710#M11115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I forget which comedian came up with this adaption of a famous quote on existence:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"I think, therefore I am...... I think?"&amp;nbsp; (unsure)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 21:49:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142710#M11115</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T21:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142711#M11116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I gave a simple example so as not to obfuscate the potential.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In reality you can create your appropriate string without the join but you need a code block.&amp;nbsp; So just pretend, that the values assigned to a-e are field names.&amp;nbsp; Then you can generate the required number of { } in the mini-language formatting in this manner.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = 12345
&amp;gt;&amp;gt;&amp;gt; b = None
&amp;gt;&amp;gt;&amp;gt; c = "some text"
&amp;gt;&amp;gt;&amp;gt; d = ""
&amp;gt;&amp;gt;&amp;gt; e = "more"
&amp;gt;&amp;gt;&amp;gt; ok_flds = [i for i in [a,b,c,d,e] if i ]
&amp;gt;&amp;gt;&amp;gt; ok_flds
[12345, 'some text', 'more']
&amp;gt;&amp;gt;&amp;gt; frmt = ("{} "*len(ok_flds)).format(*ok_flds)
&amp;gt;&amp;gt;&amp;gt; frmt
'12345 some text more '
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;Now notice that I generated the braces with a space from the length of the fields that met the ok_flds condition ie the&lt;STRONG&gt; if i&lt;/STRONG&gt; component.&amp;nbsp; Then the number of unknown fields is essentially unknown so you have to use *ok_flds ... note the star!!! to unpack the number of values from the list that is unknown in the number of braces is unknown.&amp;nbsp; If this sounds all kind of twighlighty...I posted a blog on formatting a while ago (actually several) but I am not at my link computer.&lt;/P&gt;&lt;P&gt;Once you get the hang of it, life is a lot simpler now that the formatting language exists.&amp;nbsp; The !s and !r formatting options are also particularly useful for some things ie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = np.array([1,2,3])
&amp;gt;&amp;gt;&amp;gt; print("string version...{!s}&amp;nbsp; repr version... {!r}".format(a,a))
string version...[1 2 3]&amp;nbsp; repr version... array([1, 2, 3])
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if you have nothing to do, check my posts on nothing and formatting something &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:51:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142711#M11116</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T07:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142712#M11117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan's one-line example actually has a whole bunch of things going on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;fld = &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;" "&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;.join([str(i) &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; i &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; [a,b,c,d,e] &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; i]) &lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;... can be rewritten:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;myList = []&lt;/SPAN&gt;
&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;for i in [a,b,c,d,e]:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;&amp;nbsp; if i:&lt;/SPAN&gt;
&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; myList.append(str(i))&lt;/SPAN&gt;
&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;" ".join(myList)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;Not sure if that helps or not, just a different way to read it.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:51:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142712#M11117</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T07:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142713#M11118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That helps.&amp;nbsp; But I'm curious about something.&amp;nbsp; The code as you wrote has more detail and is easier to see the pieces.&amp;nbsp; However, I see a List and Append that are not visible in the one-liner Dan posted.&amp;nbsp; I'm assuming Join is accomplishing the same thing, is that correct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the looping in Python is throwing me a bit.&amp;nbsp; How does Python know to end a loop?&amp;nbsp; This reminds me of &lt;EM&gt;If-Then&lt;/EM&gt; in other languages, but there is no explicit &lt;EM&gt;Then&lt;/EM&gt; here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:06:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142713#M11118</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T22:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142714#M11119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of if you want to stick with a list comprehension, you don't have to put a LC on one line, you can stack the syntax as follows (I posted on this as well)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; a = 12345
&amp;gt;&amp;gt;&amp;gt; b = None
&amp;gt;&amp;gt;&amp;gt; c = "some text"
&amp;gt;&amp;gt;&amp;gt; d = ""
&amp;gt;&amp;gt;&amp;gt; e = "more"
&amp;gt;&amp;gt;&amp;gt; " ".join([ str(i)
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in [a,b,c,d,e]
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i ])
'12345 some text more'
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;We obviously have too little to do on a Friday &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:52:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142714#M11119</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T07:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142715#M11120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I'm assuming Join is accomplishing the same thing, is that correct?&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Join doesn't do anything except cycle through &lt;EM&gt;a list&lt;/EM&gt;, interleaving it with &lt;EM&gt;the thing&lt;/EM&gt; (like a space). It's really the &lt;A href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions"&gt;list comprehension&lt;/A&gt; that does the magic in creating the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;How does Python know to end a loop? &lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I'm probably glazing over some subtleties, but you can think of Python "for" loops as "for each" loops. They cycle through through all the things, then quit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:15:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142715#M11120</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-06T22:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142716#M11121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a question then on List Comprehensions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using Dan's one-line example, I came up with the variation that fit my data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" ".join([str(i) for i in [ !STRNUM!, !STRNUMSUF!, !STRPREDIR!, !STRNAME!, !STRTYPE!, !STRSUFDIR! ] if i])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, the question is, does the &lt;STRONG&gt;&lt;EM&gt;for i&lt;/EM&gt;&lt;/STRONG&gt; automatically create a &lt;EM&gt;List Comprehension&lt;/EM&gt; as part of using it?&amp;nbsp; It seems like in this case it does not need to be declared, as it was in your example.&amp;nbsp; Or is there a different process going on?&amp;nbsp; I'm assuming the&lt;EM&gt;&lt;STRONG&gt; for i&lt;/STRONG&gt;&lt;/EM&gt; is a looping process - is a List Comprehension built into it?&amp;nbsp; Just curious.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142716#M11121</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2015-11-06T22:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142717#M11122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for i doesn't create the list comprehension (LC), it is used to generate the values kept in the LC.&amp;nbsp; It is useful in a variety of contexts ie&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; a = [ i for i in range(10) if i &amp;lt; 5]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; a&lt;/P&gt;&lt;P&gt;[0, 1, 2, 3, 4]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is the same as using for loops, with the exception that you dont have to append or extend list.&amp;nbsp; The principles are the same.&amp;nbsp; The utility in your context is the ability to skip a code block and simplify it down to a simple field calculation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use LCs a lot, and I don't try to go for that smokin' one liner, I usually develop them stacked in one of my other posts then de-stack them when they work.&amp;nbsp; Visually it works for me.&amp;nbsp; As was said&amp;nbsp; 6 of one, half dozen of another.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:41:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142717#M11122</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-06T22:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142718#M11123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My understanding of list comprehensions (which is limited) is that it becomes a list comprehension when it meets the following pattern:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[return elements of some sort &lt;STRONG&gt;for&lt;/STRONG&gt; something &lt;STRONG&gt;in&lt;/STRONG&gt; some iterable &lt;STRONG&gt;if&lt;/STRONG&gt; some condition] # all in an outgoing list&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure at which point Python decides that this is a list comprehension, or if that's even important. List comprehensions are a convenient way to build lists (although I find them confusing and really don't use them at all).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:43:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142718#M11123</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-11-06T22:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142719#M11124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well they are useful once you get used to them since it can simplify&amp;nbsp; existence conditions (exists) and truth values (is)&lt;/P&gt;&lt;P&gt;obj = []&lt;/P&gt;&lt;P&gt;obj_exists = isinstance(obj,list)&lt;/P&gt;&lt;P&gt;obj_is = obj is True&lt;/P&gt;&lt;P&gt;print("Exists ... {}\nTruth value... {} ".format(exists, obj_is))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result&lt;/P&gt;&lt;P&gt;Exists ... True&lt;/P&gt;&lt;P&gt;Truth value... False &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because sometimes, you want to ensure that you are working with the right object and it meets the truth condition, since iterables can be many things, and it gets more complicated when you are working with arrays because there ae more existance and truth conditions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 22:58:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142719#M11124</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-06T22:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142720#M11125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/11722"&gt;None isn't...nor is 0 or 1 ... more explorations into geometry&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/54656"&gt;Before I forget ... # 5 ... That empty feeling...&lt;/A&gt; &lt;/P&gt;&lt;P&gt;There are links within those and some comments and a blog post by &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;​ which you may find interesting to.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Also the concepts of "exists" and "is" come out of philosophy and can be exemplified in studies of symbolic logic.&amp;nbsp; Truth values complicate yet supplement these... You might be familiar with phrase "I think therefore I am" and the debate that still continues to this day.&amp;nbsp; Sooo philosophy meets geomatics perhaps &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Nov 2015 23:06:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142720#M11125</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-11-06T23:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating Strings with Field Calculator and Python - dealing with NULLS</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142721#M11126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2018 17:01:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-strings-with-field-calculator-and/m-p/142721#M11126</guid>
      <dc:creator>AndrewSmith21</dc:creator>
      <dc:date>2018-08-29T17:01:43Z</dc:date>
    </item>
  </channel>
</rss>

