<?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: Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366840#M77005</link>
    <description>&lt;P&gt;Of course! Many thanks Dan for the swift response!&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jan 2024 15:52:11 GMT</pubDate>
    <dc:creator>YusefSamari</dc:creator>
    <dc:date>2024-01-05T15:52:11Z</dc:date>
    <item>
      <title>Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366804#M76992</link>
      <description>&lt;P&gt;I am trying to populate fields with centred Easting/ Northing coordinates from a field of British National Grid grid references. I want to take different digits from the grid reference depending on its number of characters (precision). Without going into the details of BNG grid references too much, an example expression to take an Easting coordinate for me looks like this:&lt;/P&gt;&lt;P&gt;int(str(!Easting_1!)+str(!Grid_ref![2:7]))&lt;/P&gt;&lt;P&gt;If I enter this, or a slightly modified version for a different length grid reference, directly as the field calculator expression, it works fine. However, when I try to include a bunch of slightly modified versions of the above as if/else statements in the Code Block, I get an invalid syntax error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="YusefSamari_0-1704467109449.png" style="width: 527px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/90663iA5E1CD1354AE9647/image-dimensions/527x377?v=v2" width="527" height="377" role="button" title="YusefSamari_0-1704467109449.png" alt="YusefSamari_0-1704467109449.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm not sure what is going on as I am copying and pasting code from if/else statements that work fine for me elsewhere, just replacing the return value with 'int(str(!Easting_1!)+str(!Grid_ref![X:X]+"X"))', which is an expression that works fine when I use it to calculate a field directly, without the Code Block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any help much appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 15:10:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366804#M76992</guid>
      <dc:creator>YusefSamari</dc:creator>
      <dc:date>2024-01-05T15:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366835#M77003</link>
      <description>&lt;P&gt;you have to pass Easting_1 to the function&lt;/P&gt;&lt;P&gt;reclass(!Grid_ref!, !Easting_1!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(Grid_ref, Easting_1):
    if (len(Grid_ref -- 12):
        return int(str(Easting_1)  + str(Grid_ref[2:7]))
etc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;etc&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 15:48:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366835#M77003</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-01-05T15:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366840#M77005</link>
      <description>&lt;P&gt;Of course! Many thanks Dan for the swift response!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 15:52:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366840#M77005</guid>
      <dc:creator>YusefSamari</dc:creator>
      <dc:date>2024-01-05T15:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366843#M77006</link>
      <description>&lt;P&gt;The problem is the variables with the exclamation points in your code block.&amp;nbsp; Those are only allowed in the function call, as they're not actually valid Python.&amp;nbsp; It's an ArcGIS-specific implementation.&lt;/P&gt;&lt;P&gt;You first need to pass in that Easting attribute to your function call:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;reclass(!Grid_ref!, !Easting_1!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then in your code block:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def reclass(grid_ref, easting):
    if len(grid_ref) == 12:
        return int(str(easting) + str(grid_ref[2:7]))
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an aside, you don't actually need parentheses around your if clauses like that in Python if they're on a single line, but it won't hurt anything to have them.&amp;nbsp; That's really just a preference thing.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 15:54:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366843#M77006</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-01-05T15:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Unexplained syntax error in elif statements in Field Calculator Code Block for ArcGIS Pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366847#M77008</link>
      <description>&lt;P&gt;Thanks for the clear description and tip about the if clause parentheses &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2024 16:00:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/unexplained-syntax-error-in-elif-statements-in/m-p/1366847#M77008</guid>
      <dc:creator>YusefSamari</dc:creator>
      <dc:date>2024-01-05T16:00:56Z</dc:date>
    </item>
  </channel>
</rss>

