<?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: Trouble Calculating a Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335327#M26246</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan, thank you.&amp;nbsp; I played with the logic and got it to work without code def.&amp;nbsp; I hadn't thought of doing it that way, because I am attempting to duplicate a workflow that had used code def&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Dec 2014 20:49:59 GMT</pubDate>
    <dc:creator>MarkAccettulla</dc:creator>
    <dc:date>2014-12-11T20:49:59Z</dc:date>
    <item>
      <title>Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335322#M26241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know a whole lot about python and scripting, so I was hoping somebody could give me a couple pointers on fixing some python.&amp;nbsp; I am trying to calculate a "final results" attribute field.&amp;nbsp; The field type is numeric, because I want the values to either be a 1 (pass) or 0 (fail).&amp;nbsp; I have attached 2 variations of the code I have tried, but they both give me errors.&amp;nbsp; The two fields I am trying to calculate from are both text fields, and the values for both are either "PASS" or "FAIL." &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that this should be a simple task, but like I said I am very very new to python.&amp;nbsp; Any help or pointers would be much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 17:29:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335322#M26241</guid>
      <dc:creator>MarkAccettulla</dc:creator>
      <dc:date>2014-12-11T17:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335323#M26242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your 2.jpg is really close.&amp;nbsp; I think you need quotes around "FAIL" and "PASS", but not around 1 or 0.&amp;nbsp; You probably need to wrap your field names with ! as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 20:02:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335323#M26242</guid>
      <dc:creator>KevinBell</dc:creator>
      <dc:date>2014-12-11T20:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335324#M26243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Making those changes to my 2.jpg gives me an "invalid syntax" error that I wasn't getting before&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 20:12:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335324#M26243</guid>
      <dc:creator>MarkAccettulla</dc:creator>
      <dc:date>2014-12-11T20:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335325#M26244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the fields are numeric then return 0 or 1 if they are text enclose them in double quotes.&amp;nbsp; Also Pass and Fail need to be in double quotes. Also take your def into a real python IDE and test it...your indentation could be off&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also since you have so few combinations check this logic using nested if.&amp;nbsp; No code def required...not tested but you can play with the logic&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"0" if !Test1! == "Fail" else ("0" if !Test2! == "Fail" else "1")&amp;nbsp; # python of course&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 20:15:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335325#M26244</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-12-11T20:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335326#M26245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want 0 if either Test1 or Test2 = 'FAIL', and 1 if both = 'PASS", try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="kwd"&gt;def&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Final&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;t1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; t2&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;):&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;if&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; t1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;==&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'FAIL'&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;or&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; t2 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;==&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'FAIL'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;0&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;elif&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; t1 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;==&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'PASS'&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;and&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; t2 &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;==&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="str"&gt;'PASS'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;else&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;2&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="com"&gt;# this allows you to check if t1 or t2 had some other value, (except for the first case, at least one = 'FAIL')&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;return&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; val&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:53:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335326#M26245</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2021-12-11T15:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335327#M26246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan, thank you.&amp;nbsp; I played with the logic and got it to work without code def.&amp;nbsp; I hadn't thought of doing it that way, because I am attempting to duplicate a workflow that had used code def&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 20:49:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335327#M26246</guid>
      <dc:creator>MarkAccettulla</dc:creator>
      <dc:date>2014-12-11T20:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335328#M26247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greg, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you, this method also worked&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 21:04:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335328#M26247</guid>
      <dc:creator>MarkAccettulla</dc:creator>
      <dc:date>2014-12-11T21:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335329#M26248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14183695259459296" jivemacro_uid="_14183695259459296"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;"0" if !Test1! == "Fail" else ("0" if !Test2! == "Fail" else "1")&amp;nbsp; # python of course&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would argue this isn't very Pythonesque. I would not shy away from a code block if it makes it easier to debug.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Dec 2014 07:33:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335329#M26248</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-12-12T07:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335330#M26249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;their code block is unreadable...checking posts where proper indentation is often the cause has led me to use one-liners...we need a proper python mini-IDE for field calculations&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Dec 2014 07:41:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335330#M26249</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-12-12T07:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335331#M26250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Couldn't agree more. If there is any complexity I try to remember to open an IDLE window to write the code and then paste it into that ugly little dialog box.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe they should give us a button to open an IDE like with tbx script tool parameter validation code interface...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Dec 2014 08:11:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335331#M26250</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-12-12T08:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Calculating a Field</title>
      <link>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335332#M26251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One can obfuscate further by combining list comprehensions with compound comparisons with reclass&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; combined_is_best = ["Good" if x == "Curtis" else ("Best" if x == "Dan" else "Better") for x in ["Curtis","Dan","Curtis","You","get","it?"]]
&amp;gt;&amp;gt;&amp;gt; combined_is_best
['Good', 'Best', 'Good', 'Better', 'Better', 'Better']
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Though you might like this one Curtis &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:53:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-calculating-a-field/m-p/335332#M26251</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T15:53:26Z</dc:date>
    </item>
  </channel>
</rss>

