I am learning python from a book, programming python with arcgis 10.1 I did everything from Chapter 7 but I have a mistake. Here is the code import arcpy, os try: outputFC = arcpy.GetParameterAsText(0) fClassTemplate = arcpy.GetParameterAsText(1) f

3358
2
04-07-2016 12:46 AM
AlesgerMammedov3
New Contributor

I am learning python from a book, programming python with arcgis 10.1

I did everything from Chapter 7 but I have a mistake.

Here is the code

import arcpy, os
try:
  outputFC = arcpy.GetParameterAsText(0)
fClassTemplate = arcpy.GetParameterAsText(1)
  f = open(arcpy.GetParameterAsText(2),'r')
arcpy.CreateFeatureclass_management(os.path.split(outputFC)
[0], os.path.split(outputFC[1]), "point", fClassTemplate)
  lstFires = f.readlines()
  cur = arcpy.InsertCursor(outputFC)
  cntr = 1
  for fire in lstFires:
  if 'Latitude' in fire:
  continue
  vals = fire.split(",")
  latitude = float(vals[0])
  longitude = float(vals[1])
  confid = int(vals[2])
  pnt = arcpy.Point(longitude, latitude)
  feat = cur.newRow()
  feat.shape = pnt
  feat.setValue("CONFIDENCEVALUE", confid)
  cur.insertRow(feat)
  arcpy.AddMessage("Record number: " + str(cntr) + " written to
feature class")
  cntr = cntr + 1
except:
  print arcpy.GetMessages()
finally:
  del cur
  f.close()

But when I run the Code I get mistake which connect del cur.

And I do not understand why I get this mistake.

0 Kudos
2 Replies
RebeccaStrauch__GISP
MVP Esteemed Contributor

First off, it is hard to tell if you are having issues due to indentation errors, or if it is just how it is showing here.  Look at Posting Code blocks in the new GeoNet​   

The 3rd 4th and 5th 6th  line, as shown, need to be indented.

Also, it would also be helpful to see the actual error you are seeing.

PeterWilson
Regular Contributor

I've briefly had a look at your code and have made a few changes. If you could attach a sample of your input data that you are reading from as well as the template Feature Class I'd be able to help you more. Also attach a print screen of the error message that you are receiving.

# import site-packages and modules
import arcpy
import os


# set arguments
outputFC = arcpy.GetParameterAsText(0)
fClassTemplate = arcpy.GetParameterAsText(1)
f = open(arcpy.GetParameterAsText(2),'r')


# set environment settings
arcpy.env.overwriteOutput = True


try:
    output_path = os.path.split(outputFC)[0]
    output_name = os.path.split(outputFC)[1]
    arcpy.CreateFeatureclass_management(output_path, output_name, "point", fClassTemplate)
    lstFires = f.readlines()
    cur = arcpy.InsertCursor(outputFC)
    cntr = 1
    for fire in lstFires:
    if 'Latitude' in fire:
        continue
        vals = fire.split(",")
        latitude = float(vals[0])
        longitude = float(vals[1])
        confid = int(vals[2])
        pnt = arcpy.Point(longitude, latitude)
        feat = cur.newRow()
        feat.shape = pnt
        feat.setValue("CONFIDENCEVALUE", confid)
        cur.insertRow(feat)
        arcpy.AddMessage("Record number: " + str(cntr) + " written to feature class")
        cntr = cntr + 1
except:
  print arcpy.GetMessages()
finally:
    del cur
    f.close()