0

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'
  • 3
    Missing right paren on the line above. – Vince Feb 3 '17 at 0:28
3

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 on if either, but I prefer to write my code that way. – Vince Feb 3 '17 at 0:38
  • @Vince I removed the part about the print statement because to my surprise print'x' works just as well as print('x') and print '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 only print('x') actually prints x (and also works at 2.x). – PolyGeo Feb 3 '17 at 0:50
  • Yowza! That's gonna be a painful porting experience. – Vince Feb 3 '17 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 statement – Midavalo Feb 3 '17 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.