<?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: convert VB expression to python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494604#M38830</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like Adrian mentions, you will need to add some Pre-Logic code to the expression.&amp;nbsp; From the field calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Right click the field to calculate and in the Field calculator dialog, choose the appropriate Parser (ie, Python)&lt;/P&gt;&lt;P&gt;2. Place a check in the "Show Codeblock" box&lt;/P&gt;&lt;P&gt;3. In the Pre-Logic Script Code: section, add a def() that should look something like (I'm not totally certain about the exact logic desired, but this will get close I think):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def processInput(input1, input2, input3):
&amp;nbsp; if input1 == "" or input2 == "":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input3
&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input1.strip() + "" + input2.strip() + "" + input3.strip()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. In the box below the Pre-Logic script area, enter in the def() name and add your field parameters:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;processInput( !LOCN!, !LOCD!, !LOCS!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Order them appropriately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: apologies as I'm showing strictly from the Field Calculator dialog, which does not specifically address the original question of a field calculation from within a model or python script.&amp;nbsp; You will have to adapt this as needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 21:46:26 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2021-12-11T21:46:26Z</dc:date>
    <item>
      <title>convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494597#M38823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am new to python.&amp;nbsp; I am using a model to automate a data update process.&amp;nbsp; Part of the model is to calculate a new field by concatenating 3 other fields and left trimming to remove white space as needed.&amp;nbsp; Below is the VB expression.&amp;nbsp; When I use python to automatically run this model it fails at the expression to calculate the field.&amp;nbsp;&amp;nbsp; Below is the VB expression.&amp;nbsp; I cannot find an example of how this would look as a python expression.&amp;nbsp; Can anyone help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FullStreet =&lt;/P&gt;&lt;P&gt;LTrim( [LOCN] &amp;amp;" " &amp;amp;&amp;nbsp; LTrim( [LOCD] &amp;amp; " " &amp;amp;&amp;nbsp; [LOCS]))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nita L Hester&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:32:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494597#M38823</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-23T15:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494598#M38824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please note &lt;A href="https://community.esri.com/space/2004"&gt;GeoNet Help&lt;/A&gt;​ help space is for questions about GeoNet itself, not about specific programming questions. I'm moving it to the &lt;A href="https://community.esri.com/space/2145"&gt;Python&lt;/A&gt;​ space. Also, using &lt;A _jive_internal="true" href="https://community.esri.com/docs/DOC-1103"&gt;tags&lt;/A&gt; when asking questions will make it easier to be searched on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:53:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494598#M38824</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2016-02-23T15:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494599#M38825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you try .lstrip()?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So !LOCN!.lstrip() + " " + !LOCD!.lstrip() + " " + !LOCS!.lstrip()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would that work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:54:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494599#M38825</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-23T15:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494600#M38826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You'll want to look at the python help for concatenating strings. The simplest option would be as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!LOCN!.lstrip() + " " + !LOCD!.lstrip() + " " + !LOCS!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A cleaner example would be to use string.format&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"{0} {1} {2}".format(!LOCN!.lstrip(), !LOCD!.lstrip(), !LOCS!.lstrip())&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python" title="http://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python"&gt;String Concatenation and Formatting&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="http://www.tutorialspoint.com/python/string_lstrip.htm" title="http://www.tutorialspoint.com/python/string_lstrip.htm"&gt;Python String lstrip() Method&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494600#M38826</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2016-02-23T15:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494601#M38827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I tried this and it works, but I need to remove the white spaces if there is no LOCN and or LOCD data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 17:59:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494601#M38827</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-23T17:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494602#M38828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I tried this and it works, but I need to remove the white spaces if there is no LOCN and or LOCD data.&amp;nbsp; How do I remove white space from after adding it between the fields if there is no associated data for both or either of the 1st 2 fields?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 18:00:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494602#M38828</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-23T18:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494603#M38829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to use the code block to make a basic logic statement utilizing If..Then.&lt;/P&gt;&lt;P&gt;See this article on the basics for doing this:&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/manage-data/tables/calculate-field-examples.htm" title="http://desktop.arcgis.com/en/arcmap/latest/manage-data/tables/calculate-field-examples.htm"&gt;Calculate Field examples—Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and scroll down to "&lt;STRONG&gt;Using code block&lt;/STRONG&gt;s"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am guessing that you will need to check each field if it is empty or now. I would start it like:&lt;/P&gt;&lt;P&gt;If !LOCN!.len() &amp;lt;&amp;gt; 0 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(but you'll have to tinker around with the code to make it behave properly!)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 19:28:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494603#M38829</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-23T19:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494604#M38830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like Adrian mentions, you will need to add some Pre-Logic code to the expression.&amp;nbsp; From the field calculator:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Right click the field to calculate and in the Field calculator dialog, choose the appropriate Parser (ie, Python)&lt;/P&gt;&lt;P&gt;2. Place a check in the "Show Codeblock" box&lt;/P&gt;&lt;P&gt;3. In the Pre-Logic Script Code: section, add a def() that should look something like (I'm not totally certain about the exact logic desired, but this will get close I think):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def processInput(input1, input2, input3):
&amp;nbsp; if input1 == "" or input2 == "":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input3
&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input1.strip() + "" + input2.strip() + "" + input3.strip()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. In the box below the Pre-Logic script area, enter in the def() name and add your field parameters:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;processInput( !LOCN!, !LOCD!, !LOCS!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Order them appropriately.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: apologies as I'm showing strictly from the Field Calculator dialog, which does not specifically address the original question of a field calculation from within a model or python script.&amp;nbsp; You will have to adapt this as needed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:46:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494604#M38830</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T21:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494605#M38831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And to follow James' code, if you want to then call this within a python script..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def processInput(input1, input2, input3):&amp;nbsp; 
&amp;nbsp; if input1 == "" or input2 == "":&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input3&amp;nbsp; 
&amp;nbsp; else&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input1.strip() + "" + input2.strip() + "" + input3.strip()&amp;nbsp; """

# I'm showing passing three fields, but can be other input that needs to be passed
arcpy.CalculateField_management("inFC", "fieldToCal", "processInput( !field1!, !field2!, !field3!)", "PYTHON_9.3", myCode_block)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:46:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494605#M38831</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2021-12-11T21:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494606#M38832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks James! You're the best. I didn't have time to write this up and this works great.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 21:28:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494606#M38832</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-23T21:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494607#M38833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rebecca! &lt;/P&gt;&lt;P&gt;[/bookmarking this for later...]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 21:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494607#M38833</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2016-02-23T21:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494608#M38834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do it in one line with a &lt;A href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions"&gt;list comprehension&lt;/A&gt;. The `if` statement in the list comprehension will handle empty strings.&lt;/P&gt;&lt;P&gt;Field calculator expression:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14562634994606269 jive_text_macro" data-renderedposition="60_8_852_16" jivemacro_uid="_14562634994606269"&gt;&lt;P&gt;' '.join([s.lstrip() for s in (!LOCN,!LOCD!,!LOCS!) if s])&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basic python (assumes LOC* variables already defined)&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14562635846331376" data-renderedposition="128_8_852_16" jivemacro_uid="_14562635846331376"&gt;&lt;P&gt;' '.join([s.lstrip() for s in (LOCN,LOCD,LOCS) if s])&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 21:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494608#M38834</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-02-23T21:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494609#M38835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think we are getting close.&amp;nbsp; I tryed your instructions but get a syntax error on line 4.&amp;nbsp; I cannot find anything wrong though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me try to better explain what I am trying to do.&lt;/P&gt;&lt;P&gt;LOCN = House Number&lt;/P&gt;&lt;P&gt;LOCD = Street direction (i.e. N, S, E, W)&lt;/P&gt;&lt;P&gt;LOCS = Street Name (i.e Somewhere Blvd)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some records have only the LOCS.&lt;/P&gt;&lt;P&gt;Some records have the LOCN and LOCS&lt;/P&gt;&lt;P&gt;Some records have LOCN, LOCD, and LOCS&lt;/P&gt;&lt;P&gt;I need to get the end result of:&lt;/P&gt;&lt;P&gt;Somewhere Blvd, or&lt;/P&gt;&lt;P&gt;S Somewhere Blvd, or&lt;/P&gt;&lt;P&gt;1234 Somewhere Blvd, or&lt;/P&gt;&lt;P&gt;1234 S Somewhere Blvd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the VB expression it concatenates the LOCD and LOCS, then trims any space before the result so that if there is no LOCD it will only have the street name and remove the hard coded space.&amp;nbsp; LTrim( [LOCD] &amp;amp; " " &amp;amp;&amp;nbsp; [LOCS]).&amp;nbsp; Then the next part is to join that result to the first part. LTrim( [LOCN] &amp;amp;" " &amp;amp;&amp;nbsp; LTrim( [LOCD] &amp;amp; " " &amp;amp;&amp;nbsp; [LOCS]))&lt;/P&gt;&lt;P&gt;The end result is that no matter what fields have values, there are spaces when needed and no extra spaces when not.&lt;/P&gt;&lt;P&gt;Does this explain it better?&amp;nbsp; if I just do !LOCD! + !LOCS! that gives me either just the LOCS or adds the LOCD and LOCS with no space between.&amp;nbsp; That is as far as I get.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really appreciate everyones help on this!!!!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 14:17:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494609#M38835</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-24T14:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494610#M38836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/8829"&gt;Luke Pinner&lt;/A&gt;​, this is definitely the most idiomatic and elegant in my mind.&amp;nbsp; I would give 2 helpfuls if I could.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know the OP used LTRIM, which is probably why you used &lt;SPAN style="font-family: courier new,courier;"&gt;lstrip()&lt;/SPAN&gt;, but I wonder if using &lt;SPAN style="font-family: courier new,courier;"&gt;strip()&lt;/SPAN&gt; would be better for the OP.&amp;nbsp; One very minor comment, the list comprehension can be swapped for a generator expression, which then allows the expression brackets to be dropped:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1456324398066650 jive_text_macro" data-renderedposition="138.95999145507812_8_872_16" jivemacro_uid="_1456324398066650"&gt;&lt;SPAN class="string"&gt;' '.join(s.lstrip() &lt;SPAN class="keyword"&gt;for&lt;/SPAN&gt; s &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; (LOCN,LOCD,LOCS) &lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt; s)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 14:33:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494610#M38836</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-02-24T14:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494611#M38837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Total pro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 14:45:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494611#M38837</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2016-02-24T14:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494612#M38838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help.&amp;nbsp; I think we are almost there....&lt;/P&gt;&lt;P&gt;Here is the modified codeblock based on you instructions:&lt;/P&gt;&lt;P&gt;def processInput(input1, input2, input3):&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(input1) == 0 and len(input2) == 0:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif len(input1)&amp;gt;0 and input2 == "" :&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; input1 + " " + input3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif input1 == "" and len(input2)&amp;gt;0 :&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; input2 + " " + input3 &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input1 + " " + input2 + " " + input3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;processInput( !LOCN!.strip(), !LOCD!.strip(), !LOCS!.strip())&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the only problem is the first statement.&amp;nbsp; If there is no value in input 1 &amp;amp; 2 it does not return input 3. It is blank.&amp;nbsp; I tried to add the .strip to make sure there was no spaces in the field if no other value.&amp;nbsp; I also tried changing from "" to len(input1) == 0, but it still does not put a value in for just the LOCS (street name) if that is the only field that has a value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 15:15:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494612#M38838</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-24T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494613#M38839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the Calculate Field tool in my model.&amp;nbsp; how would I write this?&lt;/P&gt;&lt;P&gt;I do not know what to put in place of '&amp;nbsp; '. in your expression.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 15:23:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494613#M38839</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-24T15:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494614#M38840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may have mentioned this already, but the examples will work with TEXT field types (eg, it's possible LOCN or you address Number column is actually a number type column?).&amp;nbsp; Anyway... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if this adaptation works better.&amp;nbsp; It's just looking for empty strings (ie, "not input1") or actual strings (ie, "input1").&amp;nbsp; Also, in my sample data I thought I was looking at an empty value but it actually had a space in it --- so it was treated as an actual value and did not evaluate as expected.&amp;nbsp; This is why I included the .strip() into the input variables).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def processInput(input1, input2, input3):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (not input1.strip()) and (not input2.strip()):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input3.lstrip()
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (input1.strip()) and (not input2.strip()):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; input1 + " " + input3
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (not input1.strip()) and (input2.strip()):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; input2 + " " + input3 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return input1 + " " + input2 + " " + input3&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(I wish I could write this more elegantly like some of the other contributors!&amp;nbsp; Need to work on that)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:46:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494614#M38840</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T21:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494615#M38841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works the same as the other.&amp;nbsp; I really appreciate your help.&amp;nbsp; It still does not populate the FullStreet field when there is only a value in input3.&amp;nbsp; Everything else works though.&amp;nbsp; processInput( !LOCN!.strip(), !LOCD!.strip(), !LOCS!.strip()) (this is the Expression) Do I need to change this since it is in the code block?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(By the way this is Nita from the City of North Port.&amp;nbsp; We used to work together)&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;Nita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 17:35:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494615#M38841</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2016-02-24T17:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert VB expression to python</title>
      <link>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494616#M38842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thought so!&amp;nbsp; Hope all is well!&amp;nbsp; (City of North Port was my first consulting gig many moons ago).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll have to dig a bit to see what else might be the problem.&amp;nbsp; It's always a challenge to work thru nulls, empty strings and those that appear to be empty but are padded. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 18:06:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-vb-expression-to-python/m-p/494616#M38842</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2016-02-24T18:06:39Z</dc:date>
    </item>
  </channel>
</rss>

