<?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: ERROR 000539: SyntaxError: invalid syntax  in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600727#M46930</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am wondering if this is a valid work flow at all.&amp;nbsp; What I am really looking for is an If Then functionality, if there are rows to process then process them.&amp;nbsp; If not stop.&amp;nbsp; Am I simply trying to use the wrong tools to do that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Jan 2018 18:09:00 GMT</pubDate>
    <dc:creator>MikeChancey</dc:creator>
    <dc:date>2018-01-16T18:09:00Z</dc:date>
    <item>
      <title>ERROR 000539: SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600725#M46928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running Desktop 10.2.2.&amp;nbsp; I have been using model builder for years, creating models and exporting them to Python to automate tasks.&amp;nbsp; Recently, after a number of process failures due to broken connections, I have been trying to upgrade them to validate connections and results before continuing to the next steps.&amp;nbsp; What I wanted to do was simply check that a feature class was not empty before attempting to process&amp;nbsp;it.&amp;nbsp; For test purposes I made a very simple model to check the row count on a polygon feature class and if it were greater than 0 copy it to a new feature class.&amp;nbsp; If the count was 0 it should stop.&amp;nbsp; Really simple.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/392977_pastedImage_1.png" style="width: 620px; height: 449px;" /&gt;&lt;/P&gt;&lt;P&gt;As a model it worked perfectly, so I exported it to Python.&amp;nbsp; That produced this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# -*- coding: utf-8 -*-&lt;BR /&gt;# ---------------------------------------------------------------------------&lt;BR /&gt;# TestModel.py&lt;BR /&gt;# Created on: 2018-01-16 11:41:45.00000&lt;BR /&gt;# (generated by ArcGIS/ModelBuilder)&lt;BR /&gt;# Description: &lt;BR /&gt;# ---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Load required toolboxes&lt;BR /&gt;arcpy.ImportToolbox("Model Functions")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Local variables:&lt;BR /&gt;TestData = "C:\\Testing\\TestGeodatabase.gdb\\TestData"&lt;BR /&gt;TestPolys = "C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys"&lt;/P&gt;&lt;P&gt;# Process: Get Count&lt;BR /&gt;arcpy.GetCount_management(TestPolys)&lt;/P&gt;&lt;P&gt;# Process: Calculate Value&lt;BR /&gt;arcpy.CalculateValue_management("%Row Count% &amp;gt; 0", "", "Boolean")&lt;/P&gt;&lt;P&gt;# Process: Stop&lt;BR /&gt;arcpy.Stop_mb("true", "FALSE")&lt;/P&gt;&lt;P&gt;# Process: Feature Class to Feature Class&lt;BR /&gt;arcpy.FeatureClassToFeatureClass_conversion(TestPolys, TestData, "TestPolys2", "", "SHAPE_Length \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys,SHAPE_Length,-1,-1;SHAPE_Area \"SHAPE_Area\" false true true 8 Double 0 0 ,First,#,C:\\Testing\\TestGeodatabase.gdb\\TestData\\TestPolys,SHAPE_Area,-1,-1", "")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, that failed due to the&amp;nbsp;IOError "The toolbox file Model Functions was not found", so I deleted the portion&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# Load required toolboxes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.ImportToolbox("Model Functions")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now it generates this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\GeoProcessing\SWProcessingPythonSQL2\Scripts\TestModel.py", line 20, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.CalculateValue_management("%Row Count% &amp;gt; 0", "", "Boolean")&lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3808, in CalculateValue&lt;BR /&gt; raise e&lt;BR /&gt;ExecuteError: ERROR 000539: SyntaxError: invalid syntax (&amp;lt;expression&amp;gt;, line 1)&lt;BR /&gt;Failed to execute (CalculateValue).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why, why, why can't Model Builder export Python code that actually works?&amp;nbsp; What is the point of a WYSIWYG&amp;nbsp;GUI that doesn't produce functional code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, something is wrong with the expression.&amp;nbsp; What exactly would that be since it works in Model Builder?&amp;nbsp; This should be easy.&amp;nbsp; All I want to do is validate that there is data to process before processing it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jan 2018 17:53:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600725#M46928</guid>
      <dc:creator>MikeChancey</dc:creator>
      <dc:date>2018-01-16T17:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000539: SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600726#M46929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://pro.arcgis.com/en/pro-app/tool-reference/modelbuilder-toolbox/calculate-value.htm"&gt;&lt;STRONG&gt;CalculateValue&lt;/STRONG&gt; &lt;/A&gt;is only for use in modelbuilder, you will have to replace it with a &lt;A href="http://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm"&gt;&lt;STRONG&gt;Calculate Field&lt;/STRONG&gt;&lt;/A&gt; perhaps dumping the iterator stuff and putting it in a for loop if you need to iterate through objects&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jan 2018 17:56:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600726#M46929</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-01-16T17:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000539: SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600727#M46930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am wondering if this is a valid work flow at all.&amp;nbsp; What I am really looking for is an If Then functionality, if there are rows to process then process them.&amp;nbsp; If not stop.&amp;nbsp; Am I simply trying to use the wrong tools to do that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jan 2018 18:09:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600727#M46930</guid>
      <dc:creator>MikeChancey</dc:creator>
      <dc:date>2018-01-16T18:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000539: SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600728#M46931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you want to execute this as a Python script, or as a ModelBuilder tool? ModelBuilder&amp;nbsp;is great as a starting point but (as you notice!)&amp;nbsp;doesn't always make&amp;nbsp;functional Python, let alone efficient/elegant scripts. Conditionals are a particularly kludgy workflow within ModelBuilder, in my experience.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do a fairly straightforward&amp;nbsp;if/else conditional using the row count:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetCount_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;TestPolys&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
count &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getOutput&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; count &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;FeatureClassToFeatureClass_conversion&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;TestPolys&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; TestData&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"TestPolys2"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"there are no features in this feature class"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(Note that the &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/tools/conversion-toolbox/feature-class-to-feature-class.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;FeatureClassToFeatureClass&lt;/A&gt;&amp;nbsp;syntax can be much simpler and cleaner than ModelBuilder exports it as, too!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also do an even simpler check to see whether a feature class (or table) even exists at all, but note the &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-functions/exists.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Exists&lt;/A&gt; tool won't catch &lt;EM&gt;empty&lt;/EM&gt; feature classes.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Exists&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;TestPolys&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# do something&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"this feature class doesn't exist"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:45:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600728#M46931</guid>
      <dc:creator>EricaPfister</dc:creator>
      <dc:date>2021-12-12T01:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000539: SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600729#M46932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Excellent!&amp;nbsp; This looks like what I need to get started.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:25:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000539-syntaxerror-invalid-syntax/m-p/600729#M46932</guid>
      <dc:creator>MikeChancey</dc:creator>
      <dc:date>2018-01-17T14:25:40Z</dc:date>
    </item>
  </channel>
</rss>

