I am having some trouble converting a CSV file field values (Integers: 0 or 1 values) into string values (No Pickle Shots Pickle Shot Bar) after converting the CSV file into a point shapefile. I think it might have to do with the fact that I am making two different list? I can't seem to put my finger on it.

The specfic error I have been getting for the past few hours is as follows:
newDict = dict(it_sp[3]) ValueError: dictionary update sequence element #0 has length 1; 2 is required

Thanks in advance.

import arcpy 
import os 

bars_input = arcpy.GetParameterAsText(0)
bars_output = arcpy.GetParameterAsText(1)

#define the workspace
#makes a list of two items.. the first is the folder.. 
#the second item is the file path 
ws = os.path.split(bars_output)
#the index value 0 makes the workspace in the folder 
arcpy.env.workspace = ws[0]


#Open and read the csv file 
bars_open = open(bars_input,'r') 
bars_read = bars_open.read()

#spits the data string into a list of strings 
bars_lines = bars_read.split("\n") 

#Dictionary 
dictShots = {'0' : "No Pickle Shots", '1' : "Pickle Shot Bar"} 
new_dict = dict()

#create a empty point file 
#requires 3 inputs.. the workspace..filename..type of shapefile
arcpy.management.CreateFeatureclass(ws[0],os.path.split(bars_output)[1],"POINT") 

#Adds 2 fields to the shapefile to accommodate Name and PickleShot data 
arcpy.management.AddField(bars_output, "Name", "TEXT") 
arcpy.management.AddField(bars_output, "PickleShot", "TEXT") 


#Create an insert cursor from the blank shapefile 
#inserts rows into the attribute table
icurs = arcpy.da.InsertCursor(bars_output,["shape@","Name","PickleShot"])


#create a point object 
pnt = arcpy.Point()

i = 1 
#iterate each line of the file 
for item in bars_lines:

    if i == 1:
        i = i + 1
        continue #Skip the first row of the file 

    if item == '': 
        continue #Accounts for the last empty row of the file 
    it_sp = item.split(",") #Splits each item into a list by commas
    arcpy.AddMessage("x = %10.3f y = %10.3f" % (float(it_sp[4]), int( it_sp[5]))
    pnt.X = float(it_sp[4]) 
    pnt.Y = float(it_sp[5]) 
    newDict = dict(it_sp[3])
    icurs.insertRow([pnt, it_sp[2],(it_sp[3])])
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.