<?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 ArcGIS Pro Python Toolbox SyntaxError: invalid syntax in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1003750#M59103</link>
    <description>&lt;P&gt;I am attempting to create an&amp;nbsp;&lt;SPAN&gt;ArcGIS Pro&amp;nbsp;&lt;/SPAN&gt;Python toolbox and tool.&amp;nbsp; The script runs successfully as a standalone in Python.&amp;nbsp; But after creating the toolbox and tool, setting the parameters, and then integrating them into the source code, I am getting a Syntax Error: invalid syntax and the toolbox will not run.&amp;nbsp; I am importing arcpy, pandas, and numpy.&amp;nbsp; The syntax error first shows up in the first line of the following excerpt of the source code, where I am trying to set this parameter as an integer so that in my next line, it can run the aggregate function to calculate the mean.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        # Set data column of interest as an integer so that aggregate function of 'mean' will run
        platvlsub[parameters[1].valueAsText] = platvlsub[parameters[1].valueAsText].astype(int)

        # Create new dataframe of pivot table with the mean population density of communes on the Plateau
        platvlmn = platvlsub.pivot_table(index='Code', margins=True, margins_name='Mean_Pop_Density', aggfunc=np.mean).round(1)

        # Select just "Mean_Pop_Density" row into new dataframe
        platvlpop = platvlmn.query('Code == "Mean_Pop_Density"')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that perhaps the first line was incorrectly written, so I commented out that line.&amp;nbsp; When I do that, the syntax error simply shifts to the next line.&amp;nbsp; If I comment out that line, then it goes to the next line, and so forth.&lt;/P&gt;&lt;P&gt;Again, the error is peculiar to the&amp;nbsp;&lt;SPAN&gt;ArcGIS&lt;/SPAN&gt;&amp;nbsp;environment since the script works in Python.&amp;nbsp; The&amp;nbsp;only solution I found for this elsewhere was to disable the option to run in the background, which is already set to false in this case.&amp;nbsp; Other attempted workarounds were not successful (including rewriting the first line and shortening the variable names), thus the Toolbox will not run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running version 2.6.1 of Pro and 3.6.1 of Python.&lt;/P&gt;</description>
    <pubDate>Sun, 22 Nov 2020 02:53:27 GMT</pubDate>
    <dc:creator>ChristopherAnderson</dc:creator>
    <dc:date>2020-11-22T02:53:27Z</dc:date>
    <item>
      <title>ArcGIS Pro Python Toolbox SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1003750#M59103</link>
      <description>&lt;P&gt;I am attempting to create an&amp;nbsp;&lt;SPAN&gt;ArcGIS Pro&amp;nbsp;&lt;/SPAN&gt;Python toolbox and tool.&amp;nbsp; The script runs successfully as a standalone in Python.&amp;nbsp; But after creating the toolbox and tool, setting the parameters, and then integrating them into the source code, I am getting a Syntax Error: invalid syntax and the toolbox will not run.&amp;nbsp; I am importing arcpy, pandas, and numpy.&amp;nbsp; The syntax error first shows up in the first line of the following excerpt of the source code, where I am trying to set this parameter as an integer so that in my next line, it can run the aggregate function to calculate the mean.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;        # Set data column of interest as an integer so that aggregate function of 'mean' will run
        platvlsub[parameters[1].valueAsText] = platvlsub[parameters[1].valueAsText].astype(int)

        # Create new dataframe of pivot table with the mean population density of communes on the Plateau
        platvlmn = platvlsub.pivot_table(index='Code', margins=True, margins_name='Mean_Pop_Density', aggfunc=np.mean).round(1)

        # Select just "Mean_Pop_Density" row into new dataframe
        platvlpop = platvlmn.query('Code == "Mean_Pop_Density"')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that perhaps the first line was incorrectly written, so I commented out that line.&amp;nbsp; When I do that, the syntax error simply shifts to the next line.&amp;nbsp; If I comment out that line, then it goes to the next line, and so forth.&lt;/P&gt;&lt;P&gt;Again, the error is peculiar to the&amp;nbsp;&lt;SPAN&gt;ArcGIS&lt;/SPAN&gt;&amp;nbsp;environment since the script works in Python.&amp;nbsp; The&amp;nbsp;only solution I found for this elsewhere was to disable the option to run in the background, which is already set to false in this case.&amp;nbsp; Other attempted workarounds were not successful (including rewriting the first line and shortening the variable names), thus the Toolbox will not run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running version 2.6.1 of Pro and 3.6.1 of Python.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 02:53:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1003750#M59103</guid>
      <dc:creator>ChristopherAnderson</dc:creator>
      <dc:date>2020-11-22T02:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Python Toolbox SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1003776#M59104</link>
      <description>&lt;P&gt;&lt;EM&gt;I thought that perhaps the first line was incorrectly written, so I commented out that line.&amp;nbsp; When I do that, the syntax error simply shifts to the next line.&amp;nbsp; If I comment out that line, then it goes to the next line, and so forth.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would look back to the line &lt;U&gt;before&lt;/U&gt; the one that failed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Nov 2020 15:40:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1003776#M59104</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2020-11-22T15:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Python Toolbox SyntaxError: invalid syntax</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1004192#M59114</link>
      <description>&lt;P&gt;Thank you, curtvprice.&amp;nbsp; The previous line of code had a simple bracket missing that occurred when I brought the parameter into the source code, and I completely missed it.&amp;nbsp; Your assistance is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 01:37:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-python-toolbox-syntaxerror-invalid/m-p/1004192#M59114</guid>
      <dc:creator>ChristopherAnderson</dc:creator>
      <dc:date>2020-11-24T01:37:08Z</dc:date>
    </item>
  </channel>
</rss>

