<?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: Python Calculate Field If Statement in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6181#M19</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: niklas.norrthon&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This goes in the code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; 6: 1.2,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 85: 1.5,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2: 1.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 42: 1.8,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 58: 2.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And in the expression field you put:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights[!SYMBOL!]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 20:14:59 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-10T20:14:59Z</dc:date>
    <item>
      <title>Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6176#M14</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just wondering if the Python-Geoprocessing Community could help me.&amp;nbsp; I am trying to write the following code block into a calculate field called weight from the values in another field called Symbol.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def Reclass( !Weight!):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if ( !SYMBOL! == 6):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif ( !SYMBOL! == 85):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1.5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif ( !SYMBOL! ==2):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif ( !SYMBOL! ==42):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1.8&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif ( !SYMBOL! ==58):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It just won't work.&amp;nbsp; help...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 18:57:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6176#M14</guid>
      <dc:creator>Ryan_Galbraith</dc:creator>
      <dc:date>2011-02-14T18:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6177#M15</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're gonna have to give more info than that. And no, that method won't work.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 19:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6177#M15</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-02-14T19:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6178#M16</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;enclose your code in code blocks (# in the html editor window) so that indentation can be checked. Include a screen grab so the whole field calculator dialog window can be checked for missing elements (like how you pass the field name to the function and to make sure that the Python radiobutton is checked on)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;also any further details on the field's properties (perhaps a wrong field type, precision or scale)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 19:26:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6178#M16</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2011-02-14T19:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6179#M17</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: rdg129&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You're gonna have to give more info than that. And no, that method won't work.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This was what I was trying, but really lost track of what to put where.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 19:49:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6179#M17</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-02-14T19:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6180#M18</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just a suggestion, but if this is part of a Python script, you are &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;&lt;STRONG&gt;WAY&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; better off using an updatecursor instead. The benefit is readability, codeability, and debugging. The code block for the FieldCalculator is notoriously hard to write code for, while the updatecursor has very clear and clean syntax: &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1729&amp;amp;t=262236#806786"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1729&amp;amp;t=262236#806786&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 21:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6180#M18</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2011-02-14T21:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6181#M19</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: niklas.norrthon&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This goes in the code block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; 6: 1.2,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 85: 1.5,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2: 1.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 42: 1.8,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 58: 2.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And in the expression field you put:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights[!SYMBOL!]
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:14:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6181#M19</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T20:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6182#M20</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Just a suggestion, but if this is part of a Python script, you are &lt;SPAN style="text-decoration:underline;"&gt;&lt;STRONG&gt;WAY&lt;/STRONG&gt;&lt;/SPAN&gt; better off using an updatecursor instead. The benefit is readability, codeability, and debugging. The code block for the FieldCalculator is notoriously hard to write code for, while the updatecursor has very clear and clean syntax&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I disagree. Calculate field with short snippets of python code as in this case are perfect in most situations. The one place to avoid this tool and use an update cursor instead is within a python script, becuase of the quoting issues.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But as a stand alone tool, or in a model builder model, CalculateField is a very useful tool.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 21:50:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6182#M20</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2011-02-14T21:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6183#M21</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: csny490&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are going the Python route, I still assert that a cursor is better because:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. It's faster and easier to write the code (no need to post to the forums per the pain in the ass \\n\\n\\n shinanigans).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. When you print the code it's actually understandable by a human, where as the codeblock generally comes out in one big line and is generally unintelligible. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example (yes this is VB, but you get my drift):&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;KLAScodeblock = "If [CMPAREA] &amp;lt;= 1000 Then\\nklasse = 100\\n\\nElseif [MIN] &amp;lt;= "+MDV+"&amp;nbsp; Then \\nklasse = 1\\n\\nElseif [MIN] &amp;lt;= "+MDA+" Then \\nklasse = 2\\n\\nElse \\nklasse = 3\\n\\nEnd&amp;nbsp; If\\n\\n\\n"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Feb 2011 22:03:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6183#M21</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-02-14T22:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6184#M22</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This goes in the code block:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; 6: 1.2,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 85: 1.5,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2: 1.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 42: 1.8,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 58: 2.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt; &lt;BR /&gt;And in the expression field you put:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights[!SYMBOL!]
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks good, but I am still getting an error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I put in.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #e60000; font-size: 5;"&gt;&lt;SPAN style="color: #e60000; font-size: 5;"&gt;ERROR &lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #480004; font-size: 5;"&gt;000539&lt;/SPAN&gt;&lt;SPAN style="color: #e60000; font-size: 5;"&gt;: Error running expression: SYMBOL_weights[2] &amp;lt;type 'exceptions.NameError'&amp;gt;: name 'SYMBOL_weights' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #e60000; font-size: 5;"&gt;&lt;BR /&gt; &lt;BR /&gt;Failed to execute (Calculate Field).&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #9c9c9c; font-size: 5;"&gt; &lt;BR /&gt;Failed at Wed Feb 16 13:17:20 2011 (Elapsed Time: 1.00 seconds)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:15:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6184#M22</guid>
      <dc:creator>Ryan_Galbraith</dc:creator>
      <dc:date>2021-12-10T20:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6185#M23</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;let us examine how Python is used in the field calculator as indicated from the help files....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s0000002m000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is an Expression box, and a Code block, in the code block there is a section for variables and/or imports to be denoted (in this case an import statement) and a&amp;nbsp; Python function, as denoted by the &lt;/SPAN&gt;&lt;STRONG&gt;def&lt;/STRONG&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the syntax is correct and the fieldname is enclosed in double !'s then it should work&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Parser:
Python

Expression:
getRandomValue()

Code Block:
import numpy.random as R

def getRandomValue():
&amp;nbsp;&amp;nbsp;&amp;nbsp; return R.random()

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;can you get this to work in a field?&amp;nbsp; The error in the previous example is that SYMBOL_weights is not a function&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6185#M23</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-10T20:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6186#M24</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: niklas.norrthon&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tested it and got the same error, and I still don't understand why. But I found an easy workaround: Rename the dictionary to something else (without underscore) like symweights. Do that both in the code block and the expression field and it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 19:12:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6186#M24</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-02-16T19:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6187#M25</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I tested it and got the same error, and I still don't understand why. But I found an easy workaround: Rename the dictionary to something else (without underscore) like symweights. Do that both in the code block and the expression field and it works.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That works perfect.&amp;nbsp; Like Python should!&amp;nbsp; Amazing.&amp;nbsp; I choose this method, because I wanted to use the ModelBuilder.&amp;nbsp; Not sure if a cursor would work in this case.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Feb 2011 19:39:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6187#M25</guid>
      <dc:creator>Ryan_Galbraith</dc:creator>
      <dc:date>2011-02-16T19:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6188#M26</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: niklas.norrthon&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That works perfect.&amp;nbsp; Like Python should!&amp;nbsp; Amazing.&amp;nbsp; I choose this method, because I wanted to use the ModelBuilder.&amp;nbsp; Not sure if a cursor would work in this case.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A cursor would work just as well (untested):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
symbol_weights = {
&amp;nbsp;&amp;nbsp;&amp;nbsp; 6: 1.2,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 85: 1.5,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2: 1.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 42: 1.8,
&amp;nbsp;&amp;nbsp;&amp;nbsp; 58: 2.0,
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

cur = arcpy.UpdateCursor(my_feature_class)
for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Weight = symbol_weights[row.SYMBOL]
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur.UpdateRow(row)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:15:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6188#M26</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T20:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6189#M27</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Cursor works better!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Nov 2011 17:14:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6189#M27</guid>
      <dc:creator>Ryan_Galbraith</dc:creator>
      <dc:date>2011-11-22T17:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculate Field If Statement</title>
      <link>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6190#M28</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ryan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you define the method within the Python codeblock, use a variable for the Reclass method's parameter and use that variable within the method's logic:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def Reclass(weight):&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (weight == 6):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1.2&lt;/P&gt;&lt;P&gt;&amp;nbsp; elif (weight == 85):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 85&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then when you call the Reclass method in the Calculate Field Expression parameter, you will then pass in the SYMBOL field:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reclass(!SYMBOL!)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Sep 2014 17:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/python-calculate-field-if-statement/m-p/6190#M28</guid>
      <dc:creator>AndyOmmen</dc:creator>
      <dc:date>2014-09-09T17:28:31Z</dc:date>
    </item>
  </channel>
</rss>

