<?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: Learning Python- Needing help with If/Then Field Calculator Script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503150#M71020</link>
    <description>&lt;P&gt;The conditions are evaluated in order so put the most important one first and use &lt;FONT face="courier new,courier"&gt;elif&lt;/FONT&gt; for the other conditions. You'll also need to update the parameters in your function to accept Field2.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Expression
Reclass(!Field1!, !Field2!)

# Code Block
def Reclass(field1, field2):
    if field2 == "y":
        return "4"
    elif field1=="x":
        return "1"
    elif field1 =="y":
        return "2"
    else:
        return "3"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2024 17:58:15 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2024-07-09T17:58:15Z</dc:date>
    <item>
      <title>Learning Python- Needing help with If/Then Field Calculator Script</title>
      <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503138#M71017</link>
      <description>&lt;P&gt;Hello! I am very very new to Python and am needing help creating a script for Field Calculator and am having trouble finding an online resource- hoping someone here could help me! I created a script that populates a new field based off of existing attributes in an existing field but am needing to add a caveat that if another case is true, then this other condition supersedes all other conditions.&lt;/P&gt;&lt;P&gt;ie I currently have something along the lines of:&amp;nbsp;&lt;/P&gt;&lt;P&gt;def Reclass(field1):&lt;/P&gt;&lt;P&gt;if (field 1=='x'):&lt;/P&gt;&lt;P&gt;return "1"&lt;/P&gt;&lt;P&gt;if (field 1 =='y'):&lt;/P&gt;&lt;P&gt;return "2"&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;return "3"&lt;/P&gt;&lt;P&gt;But I want to add something that says that no matter what is in field 1, if field 2 == y, return 4: a condition to supersede all the other conditions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 17:50:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503138#M71017</guid>
      <dc:creator>Gtech301</dc:creator>
      <dc:date>2024-07-09T17:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Learning Python- Needing help with If/Then Field Calculator Script</title>
      <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503148#M71019</link>
      <description>&lt;P&gt;Should be straightforward.&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(field1, field2):
    # Check field2 and then immediately exit if it works.
    if field2 == "y":
        return 4
    # Start checking field1.
    if field1 == "x":
        return "1" 
    elif field1 == "y":
        return "2" 
    else:
        return "3"&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 Jul 2024 17:57:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503148#M71019</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-07-09T17:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Learning Python- Needing help with If/Then Field Calculator Script</title>
      <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503150#M71020</link>
      <description>&lt;P&gt;The conditions are evaluated in order so put the most important one first and use &lt;FONT face="courier new,courier"&gt;elif&lt;/FONT&gt; for the other conditions. You'll also need to update the parameters in your function to accept Field2.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Expression
Reclass(!Field1!, !Field2!)

# Code Block
def Reclass(field1, field2):
    if field2 == "y":
        return "4"
    elif field1=="x":
        return "1"
    elif field1 =="y":
        return "2"
    else:
        return "3"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 17:58:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503150#M71020</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-07-09T17:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Learning Python- Needing help with If/Then Field Calculator Script</title>
      <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503161#M71021</link>
      <description>&lt;P&gt;Thanks, really appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 18:09:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503161#M71021</guid>
      <dc:creator>Gtech301</dc:creator>
      <dc:date>2024-07-09T18:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Learning Python- Needing help with If/Then Field Calculator Script</title>
      <link>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503162#M71022</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 18:09:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/learning-python-needing-help-with-if-then-field/m-p/1503162#M71022</guid>
      <dc:creator>Gtech301</dc:creator>
      <dc:date>2024-07-09T18:09:14Z</dc:date>
    </item>
  </channel>
</rss>

