<?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: Error running field calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248885#M19237</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;still learning python myself, but you might try None instead of null&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Jul 2011 14:28:14 GMT</pubDate>
    <dc:creator>TerrySilveus</dc:creator>
    <dc:date>2011-07-13T14:28:14Z</dc:date>
    <item>
      <title>Error running field calculator</title>
      <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248884#M19236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to copy over values from a string field to an integer field. In the case of an empty string, I want to make the value null but am getting the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: Error running expression: getDOT( " ") &amp;lt;type 'exceptions.NameError'&amp;gt;: global name 'null' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Calculate Field (7))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code block that I am using the field calculator is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def getDOT(dot):

&amp;nbsp; if (len(dot) &amp;gt; 1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(dot)
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = null

&amp;nbsp; return result&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible to set integer field to a null value? I have done it in the past, but cannot seem to get it to work now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;jeremy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 17:31:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248884#M19236</guid>
      <dc:creator>deleted-user-rQoEFM5qzbHE</dc:creator>
      <dc:date>2011-07-12T17:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Error running field calculator</title>
      <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248885#M19237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;still learning python myself, but you might try None instead of null&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2011 14:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248885#M19237</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2011-07-13T14:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error running field calculator</title>
      <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248886#M19238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is another issue I am having. This string field has values that are not numbers. For example, one of the records has a value of 'UNKNOWN'. Since I am copying these values over to an integer field, this record should have a value of 0. However, I cannot figure out how to catch for this type of situation. Here is the code I am trying to use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def getDOT(dot):

&amp;nbsp; if (isinstance(int(dot), int)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(dot)
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = None

&amp;nbsp; return result&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It doesn't like the second line.When it tries to convert the above example to an int, it crashes. This makes sense, but I cannot seem to figure out another way to approach this problem. Anybody have any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;jeremy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:23:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248886#M19238</guid>
      <dc:creator>deleted-user-rQoEFM5qzbHE</dc:creator>
      <dc:date>2021-12-11T12:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error running field calculator</title>
      <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248887#M19239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should use a try/except statement &lt;/SPAN&gt;&lt;A href="http://docs.python.org/tutorial/errors.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://docs.python.org/tutorial/errors.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;def getDOT(dot):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def getDOT(dot):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(dot)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = Null
&amp;nbsp;&amp;nbsp;&amp;nbsp; finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:23:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248887#M19239</guid>
      <dc:creator>ChristopherFricke1</dc:creator>
      <dc:date>2021-12-11T12:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error running field calculator</title>
      <link>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248888#M19240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;and I'm not sure of your purposes, but you may not want to make an "UNKNOWN" 0 because 0 may be a legitimate value, it would probably be better to make that value NULL which christophfricke's code should do for you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2011 21:21:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-running-field-calculator/m-p/248888#M19240</guid>
      <dc:creator>TerrySilveus</dc:creator>
      <dc:date>2011-07-18T21:21:51Z</dc:date>
    </item>
  </channel>
</rss>

