<?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 Python ArcGIS 10.1 Field Calculator If...Then Issue with None in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62397#M5026</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created a simple 'Code Block' python script for the Field Calculator in ArcGIS 10. It was working fine then. Since I installed ArcGIS 10.1, something strange is happening when I run it. The purpose is to concatenate 3 different text fields into a new field as Provincial Code (2 numbers) + Trail Code (4 numbers) + Section Code (1 letter). Provincial Code and Trail codes don't have Null values but the Section code has Null value in it. So when a section code exist, the Project Code will look like 01-0001A but with look like 01-0001 if no section code exists. Here is the 'Code Block' I'm using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Expression = classify(!ID_Province!, !ID_Trail!, str(!ProjSection!))&amp;nbsp; def classify(prov, trail, section): &amp;nbsp; if section == "": &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail &amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + section&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So when the Section code is Null or empty, I want to concatenate provincial and trail only (don't want any space or anything else after). Then, if a section code exist, I want to concatenate all of them together. As I said, it was working fine in ArcGIS 10. With ArcGIS 10.1, the code seems to only calculate the 'else' statement. If a section code exist, the code returns as expected something like 01-0001A. However, if section code is Null, instead of having something like 01-0001 I have 01-0001None. I don't understand why None appears now at the end.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Jul 2012 15:35:03 GMT</pubDate>
    <dc:creator>Charles-AndreRoy</dc:creator>
    <dc:date>2012-07-03T15:35:03Z</dc:date>
    <item>
      <title>Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62397#M5026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created a simple 'Code Block' python script for the Field Calculator in ArcGIS 10. It was working fine then. Since I installed ArcGIS 10.1, something strange is happening when I run it. The purpose is to concatenate 3 different text fields into a new field as Provincial Code (2 numbers) + Trail Code (4 numbers) + Section Code (1 letter). Provincial Code and Trail codes don't have Null values but the Section code has Null value in it. So when a section code exist, the Project Code will look like 01-0001A but with look like 01-0001 if no section code exists. Here is the 'Code Block' I'm using:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Expression = classify(!ID_Province!, !ID_Trail!, str(!ProjSection!))&amp;nbsp; def classify(prov, trail, section): &amp;nbsp; if section == "": &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail &amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + section&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So when the Section code is Null or empty, I want to concatenate provincial and trail only (don't want any space or anything else after). Then, if a section code exist, I want to concatenate all of them together. As I said, it was working fine in ArcGIS 10. With ArcGIS 10.1, the code seems to only calculate the 'else' statement. If a section code exist, the code returns as expected something like 01-0001A. However, if section code is Null, instead of having something like 01-0001 I have 01-0001None. I don't understand why None appears now at the end.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 15:35:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62397#M5026</guid>
      <dc:creator>Charles-AndreRoy</dc:creator>
      <dc:date>2012-07-03T15:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62398#M5027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Modify your codeblock slightly. Instead of testing a certain value ("") for section, use the generic statement whether section has some value. Your code should look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def classify(prov, trail, section):
&amp;nbsp; if section:&amp;nbsp; # if section has any value
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + section
&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; # if section is empty or null or None
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62398#M5027</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2021-12-10T22:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62399#M5028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Modify your codeblock slightly. Instead of testing a certain value ("") for section, use the generic statement whether section has some value. Your code should look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def classify(prov, trail, section):
&amp;nbsp; if section:&amp;nbsp; # if section has any value
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + section
&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp; # if section is empty or null or None
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Ahmed for your quick reply. However, I'm still facing the same issue...None appears at the end each time I have Null value as section code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:23:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62399#M5028</guid>
      <dc:creator>Charles-AndreRoy</dc:creator>
      <dc:date>2021-12-10T22:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62400#M5029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="plain" name="code"&gt;Expression = classify(!ID_Province!, !ID_Trail!, !ProjSection!)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;And&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def classify(prov, trail, section): &amp;nbsp; if section: &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail &amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + (str(section) if section else '')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 18:14:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62400#M5029</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-07-03T18:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62401#M5030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Expression = classify(!ID_Province!, !ID_Trail!, !ProjSection!)
&lt;/PRE&gt;&lt;BR /&gt;And&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def classify(prov, trail, section):
&amp;nbsp; if section:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + section
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return prov + "-" + trail + (str(section) if section else '')&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much Jason. I don't really understand why I need to do this, but it's working now. I read somewhere that for Null values we had to put str in the expression and not in the code block. Can you explain the logic behind this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:23:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62401#M5030</guid>
      <dc:creator>Charles-AndreRoy</dc:creator>
      <dc:date>2021-12-10T22:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python ArcGIS 10.1 Field Calculator If...Then Issue with None</title>
      <link>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62402#M5031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Null values used to behave somewhat inconsistently; now they are correctly treated as the python value &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;None&lt;/SPAN&gt;&lt;SPAN&gt; across the system. You can do something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;if value is None&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;now in places to test if a value is &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;Null &lt;/SPAN&gt;&lt;SPAN&gt;in the table.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 19:34:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-arcgis-10-1-field-calculator-if-then-issue/m-p/62402#M5031</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-07-03T19:34:53Z</dc:date>
    </item>
  </channel>
</rss>

