Question: I am trying to delete first and the last vertex of each line. 

I created code to delete first and last vertex but it shows me error on line 18:

> 
> 
> > 
> > Traceback (most recent call last): File "D:\UKPN\ukpn\_CAD\tet\Delete\_first\_last.py", line 18, in 
> >  insert = arcpy.da.InsertCursor(outFC, "SHAPE@") RuntimeError: cannot open
> >  'D:\UKPN\ukpn\_CAD\ukpn\_CAD.gdb\right\_no\_diss\_sample\_diss\_Sp4' Failed
> >  to execute (Deletefirstlast).
> > 
> > 
> > 
> 
> 
> 

My code:

```
import arcpy

arcpy.env.overwriteOutput = True

# set input/output parameters
inFC = arcpy.GetParameterAsText(0)      
outFC = arcpy.GetParameterAsText(1)    

#output path
fcPath = outFC.rpartition("\\")[0]
fcName = outFC.rpartition("\\")[2]

if arcpy.Exists(outFC):
    arcpy.Delete_management(outFC)

search = arcpy.da.SearchCursor(inFC, "SHAPE@")
insert = arcpy.da.InsertCursor(outFC, "SHAPE@")

for row in search:
    points = [arcpy.Point(point.X, point.Y) for shape in row[0] for point in shape]

    del points[0]
    del points[-1]
    points.append(points[0])

    array = arcpy.Array(points)
    polyline = arcpy.Polyline(array)

    insert.insertRow([polyline])

```

I am using ArcGIS Pro Basic license 1.3. Can anyone tell me what am I doing wrong?

Answer: 
I think the problem lies in your attempt to "explode" your geometry into a list of point objects. I personally find list comprehension extremely confusing and generally unreadable. The following code does the same and is much easier to read.

```py
# Code assumes the following: all polylines are single part & that a minimum number of vertices is 4
import arcpy
flayer = "fcLines" # Layer in TOC
with arcpy.da.UpdateCursor(flayer,["shape@","OID@"]) as cursor:
    for row in cursor:
        geom = row[0]
        oid = row[1]
        if geom.length > 0:
            # Create an array of point
            arr = geom.getPart(0) 

            print "Processing OID: " + str(oid)
            print "before: " + str(arr.count)

            # remove first
            arr.remove(0)

            # remove end
            arr.remove(arr.count - 1)

            print "after: " + str(arr.count)

            # Create new polyline and update row
            newLine = arcpy.Polyline(arr)
            row[0] = newLine
            cursor.updateRow(row)

```

Looking at your initial attempt there is no error trapping, what about lines that are composed of only two vertices, what about null geometries, what about stacked points? You need to deal with all those situations, you cannot assume your dataset is perfect.
You are asking your model's user to enter an output feature class location/name as a parameter and deleting it if it exists. The problem is arcpy.da.InsertCursor works only with existing feature classes, so you need to create one (since you want to make sure it is an empty feature class). 

Try adding [Create Feature Class tool](http://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-feature-class.htm) just before your insert cursor with relevant out path, name and geometry arguments.

Also the rest of your code may not work as expected if you have multipartite polylines!