<?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 Field Calculator Python - Comparing one field to the next in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236427#M18398</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have the following syntax in a coded block script in field calculator using python and a personal geodatabase feature class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if !ECOSITE! == !ECOSITE_1!: &amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Same" else: &amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Inclusion"&amp;nbsp; COMPARE_FIELDS =&amp;nbsp; test&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe it's a Monday morning and I just can't seem to figure out why it's erroring out, but it is. I am getting one or 2 error numbers....the generic 999999 and another generic one 000989. Neither one of which are revealing why the calculator doesn't like my equation. Can anyone identify what it going wrong? I've also attached a screenshot of my field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]13186[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Apr 2012 17:06:24 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2012-04-02T17:06:24Z</dc:date>
    <item>
      <title>Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236427#M18398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have the following syntax in a coded block script in field calculator using python and a personal geodatabase feature class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if !ECOSITE! == !ECOSITE_1!: &amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Same" else: &amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Inclusion"&amp;nbsp; COMPARE_FIELDS =&amp;nbsp; test&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe it's a Monday morning and I just can't seem to figure out why it's erroring out, but it is. I am getting one or 2 error numbers....the generic 999999 and another generic one 000989. Neither one of which are revealing why the calculator doesn't like my equation. Can anyone identify what it going wrong? I've also attached a screenshot of my field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]13186[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 17:06:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236427#M18398</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-04-02T17:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236428#M18399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Python is a bit different for its setup.&amp;nbsp; You need to have a function definition and a call to the function.&amp;nbsp; Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def TestFields (Field1,Field2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Field1 == Field2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Same"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Inclusion"

COMPARE_FIELDS = 
TestFields(!ECOSITE!,!ECOSITE_1!)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cory&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:55:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236428#M18399</guid>
      <dc:creator>CoryMacNeil1</dc:creator>
      <dc:date>2021-12-11T11:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236429#M18400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks for the response Cory. Unfortunately this still is returning the same errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def TestFields ( !ECOSITE! , !ECOSITE_1! ):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if !ECOSITE_1! == !ECOSITE!:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Same"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; test = "Inclusion"

COMPARE_FIELDS = 
TestFields(!ECOSITE!,!ECOSITE_1!)

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I even tried returning the "test" variable and same deal...I'm stumped. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I don't think you need to define a function in the field calculator in code block mode. I have other conditional scripts that work without defining them as functions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:55:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236429#M18400</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-11T11:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236430#M18401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mike, you're getting close. It's a funny syntax thing - in the expression you reference fields (e.g. !ECOSITE!), then they turn into arguments/variables in the function (e.g. ECOSITE). Then, "return" the values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def TestFields ( ECOSITE , ECOSITE_1 ): # these reference individual values &amp;nbsp;&amp;nbsp;&amp;nbsp; if ECOSITE_1 == ECOSITE: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Same" &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Inclusion"&amp;nbsp; COMPARE_FIELDS =&amp;nbsp; TestFields(!ECOSITE!,!ECOSITE_1!) # these reference the field to grab individual values&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 17:50:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236430#M18401</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-02T17:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236431#M18402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mike,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With Python, I am quite certain you do have to define a function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this (I forgot the return in my first posting):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def TestFields (Field1,Field2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Field1 == Field2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Same"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Inclusion"

TEST =
TestFields( !ECOSITE!, !ECOSITE_1! )
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;I just did a sample and it works.&amp;nbsp; If it does not work for you, let me know what data types your two ECOSITE fields are.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cory&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:55:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236431#M18402</guid>
      <dc:creator>CoryMacNeil1</dc:creator>
      <dc:date>2021-12-11T11:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator Python - Comparing one field to the next</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236432#M18403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey thanks folks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Darren that works. I started playing around with returning the values. Thanks for pointing me in the right direction&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cory, looks like you followed up the same thought. Also, you are right about defining functions. I was looking at an older script of mine, but it turns out it was in VB. My bad!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 18:21:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-python-comparing-one-field-to-the/m-p/236432#M18403</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-04-02T18:21:06Z</dc:date>
    </item>
  </channel>
</rss>

