<?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: caculate field python invaild syntax in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252676#M64765</link>
    <description>&lt;P&gt;Dan's method above of selecting target records and then calculating on the selected records is a safe, easy and effective way to do this. Be sure to work on a copy of data when experimenting or alternately make sure that Undo is enabled so you can Discard edits when things go wrong.&lt;/P&gt;&lt;P&gt;Consider the option below:&lt;/P&gt;&lt;P&gt;Python is fussy about indentation and colons:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BarryNorthey_0-1674960389660.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61547i26D8B8B1951D98AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BarryNorthey_0-1674960389660.png" alt="BarryNorthey_0-1674960389660.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 29 Jan 2023 02:55:06 GMT</pubDate>
    <dc:creator>BarryNorthey</dc:creator>
    <dc:date>2023-01-29T02:55:06Z</dc:date>
    <item>
      <title>caculate field python invaild syntax</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252666#M64761</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I'm a newbie for python, trying to fill the &amp;lt;Null&amp;gt;&amp;nbsp; into 04 by using the "Caculate Field" function.&lt;/P&gt;&lt;P&gt;But it says I got some invaild syntax, not sure what's goion on after searching some tutorials on the internet.&lt;/P&gt;&lt;P&gt;I wan't to know how to make it work, thanks.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="螢幕擷取畫面 2023-01-29 082443.png" style="width: 849px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61544iC0211BC686B62E98/image-size/large?v=v2&amp;amp;px=999" role="button" title="螢幕擷取畫面 2023-01-29 082443.png" alt="螢幕擷取畫面 2023-01-29 082443.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;Teng-Wei.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 00:42:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252666#M64761</guid>
      <dc:creator>WilliamYu811</dc:creator>
      <dc:date>2023-01-29T00:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: caculate field python invaild syntax</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252672#M64764</link>
      <description>&lt;P&gt;re&amp;nbsp; .... is the name of a python module change the function name, or perhaps use the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="isnull.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61545iBAD4FAFF0235315A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="isnull.png" alt="isnull.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="isnull2.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61546iC93C4CFAA4AFA3E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="isnull2.png" alt="isnull2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 02:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252672#M64764</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-29T02:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: caculate field python invaild syntax</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252676#M64765</link>
      <description>&lt;P&gt;Dan's method above of selecting target records and then calculating on the selected records is a safe, easy and effective way to do this. Be sure to work on a copy of data when experimenting or alternately make sure that Undo is enabled so you can Discard edits when things go wrong.&lt;/P&gt;&lt;P&gt;Consider the option below:&lt;/P&gt;&lt;P&gt;Python is fussy about indentation and colons:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BarryNorthey_0-1674960389660.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61547i26D8B8B1951D98AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BarryNorthey_0-1674960389660.png" alt="BarryNorthey_0-1674960389660.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 02:55:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252676#M64765</guid>
      <dc:creator>BarryNorthey</dc:creator>
      <dc:date>2023-01-29T02:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: caculate field python invaild syntax</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252689#M64766</link>
      <description>&lt;P&gt;!LOC! if !LOC! else "04"&lt;/P&gt;&lt;P&gt;Will do the same since &amp;lt;NULL&amp;gt; is effectively None&lt;/P&gt;&lt;P&gt;emulating a file in a table called LOC&lt;/P&gt;&lt;LI-CODE lang="python"&gt;LOC =['A', 'B', None, "D"]

[i if i else "04" for i in LOC]
Out[12]: ['A', 'B', '04', 'D']&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 29 Jan 2023 11:25:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252689#M64766</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-01-29T11:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: caculate field python invaild syntax</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252699#M64768</link>
      <description>&lt;P&gt;As pointed out by&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/598043"&gt;@BarryNorthey&lt;/a&gt;&amp;nbsp;the specific syntax error you are getting is due to a lack of a colon after your function definition line.&lt;/P&gt;&lt;P&gt;Since you are new to Python, I will also point out that best practice according to&amp;nbsp;&lt;A href="https://peps.python.org/pep-0008/" target="_blank" rel="noopener"&gt;https://peps.python.org/pep-0008/&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Comparisons to singletons like None should always be done with &lt;SPAN class=""&gt;is&lt;/SPAN&gt; or &lt;SPAN class=""&gt;is&lt;/SPAN&gt; &lt;SPAN class=""&gt;not&lt;/SPAN&gt;, never the equality operators.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, in this case your syntax should &lt;U&gt;not&lt;/U&gt; be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if ( LC01 == None ) :   # which by the way you forgot another colon.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if ( LC01 is None ) :&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;has already pointed out, for a simple conditional check like this you can rely on &lt;A href="https://docs.python.org/3/reference/expressions.html#conditional-expressions" target="_self"&gt;Python's conditional expression&lt;/A&gt;, aka ternary operator, to handle it rather than defining a function in the code block.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"04" if !LC01! is None else !LC01!&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Jan 2023 16:16:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/caculate-field-python-invaild-syntax/m-p/1252699#M64768</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-29T16:16:38Z</dc:date>
    </item>
  </channel>
</rss>

