I was working through an exercise designed to teach basic Python skills in ArcMap using Python 2.7. The file below consists of 34 pairs of x,y coordinates. The script creates a new empty polyline feature class, and then use this list of coordinates to create a new polyline. This requires the use of an insert cursor to create new rows and an array object to contain the point objects. Here is the original proposed script:
import arcpy import fileinput import string import os from arcpy import env env.workspace = "C:/Workspace" env.overwriteOutput = True arcpy.CreateFeatureclass_management(r"C:/Results", "newfc", "POLYLINE", None, "DISABLED", "DISABLED", None, None, 0, 0, 0, None) infile = "C:/coordinates.txt" cursor = arcpy.da.InsertCursor("newfc.shp", ["SHAPE@"]) array = arcpy.Array() for line in fileinput.FileInput(infile): ID, X, Y = (float(infile.split(line," ")) array.add(arcpy.Point(X, Y)) cursor.insertRow([arcpy.Polyline(array)]) fileinput.close() del cursor
However, there is a syntax error related to the arcpy.Array() method.
File "C:/create.py", line 21 array.add(arcpy.Point(X, Y)) ^ SyntaxError: invalid syntax
Here is the point file.
My knowledge is limited and wondered if someone knows if this is a Python version issue and where to find more info, or if they have an answer to the syntax error problem I articulated above.