I am trying to get a search cursor to go through each row and Multi buffer a feature.
I keep getting a syntax error with no error codeother than Invalid Syntax (traceback to this line of code) so i am assuming its something I am doing in the calling of the multiring buffer.
Error Message:
C:\Python27\ArcGIS10.3\python.exe N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Script\SearchCUrsor.py
File "N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Script\SearchCUrsor.py", line 19
arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL")
^
SyntaxError: invalid syntax
Code below
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
file_workspace = "r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb"
env.workspace = file_workspace
Var_Polygonname = row[0]
Holdings = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb\Data\Holdings'
ofc = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb'
distances = [1000, 4000]
unit = "Meters"
arcpy.MakeFeatureLayer_management(Holdings,'Holdings_Layer')
with arcpy.da.SearchCursor(Holdings, ['Holding_Reference_Number'])as Holdings_Ref_cursor:
for x in Holdings_Ref_cursor:
print x[0] + Var_Polygonname
arcpy.SelectLayerByAttribute_management('Holdings_Layer', 'NEW_SELECTION', '"Holding_Reference_Number" = \'Var_Polygonname\''
arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL")
#arcpy.Buffer_analysis("Holdings_Layer", ofc, var_Buffer, "FULL", "ROUND", "ALL", "")
print'Buffer complete'
-
3Missing right paren on the line above.Vince– Vince2017年02月03日 00:28:01 +00:00Commented Feb 3, 2017 at 0:28
1 Answer 1
On the first line below (as @Vince commented) there is a missing right parenthesis at the end of the line. The error message appears to be telling you that there is a problem on the arcpy.MultipleRingBuffer_analysis()
line but because the previous line is unfinished it is really saying "on this line or the line before that I think is part of it".
Instead of:
arcpy.SelectLayerByAttribute_management('Holdings_Layer', 'NEW_SELECTION', '"Holding_Reference_Number" = \'Var_Polygonname\''
arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL")
try this:
arcpy.SelectLayerByAttribute_management('Holdings_Layer', 'NEW_SELECTION', '"Holding_Reference_Number" = \'Var_Polygonname\'')
arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL")
-
Parens are not required on
print
statements (it's not a function). They're not required onif
either, but I prefer to write my code that way.Vince– Vince2017年02月03日 00:38:56 +00:00Commented Feb 3, 2017 at 0:38 -
@Vince I removed the part about the
print
statement because to my surpriseprint'x'
works just as well asprint('x')
andprint 'x'
at Python 2.x. However, for Python 3.x which I'm trying to ready ArcPy users for wherever possible,print'x'
=>SyntaxError: invalid syntax
,print 'x'
=>SyntaxError: Missing parentheses in call to 'print'
, and onlyprint('x')
actually printsx
(and also works at 2.x).2017年02月03日 00:50:58 +00:00Commented Feb 3, 2017 at 0:50 -
Yowza! That's gonna be a painful porting experience.Vince– Vince2017年02月03日 01:00:37 +00:00Commented Feb 3, 2017 at 1:00
-
That has been the hardest thing for me, both in porting and in just typing raw code - including the parentheses on a
print
statement2017年02月03日 01:31:14 +00:00Commented Feb 3, 2017 at 1:31