1

Here is the code block that I am using with ArcGIS 10.2 for Desktop, it all works great except for the bottom part. I am not sure how to turn the tuple into records on a blank feature class. The tuple looks like this: ('BRONTE DR', 'BRONTE DR', 'RICHARDSON DR', 'RICHARDSON DR'). I want each part of the tuple to be a new record in the blank feature class.

import re
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
if arcpy.Exists(r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets2"):
    arcpy.Delete_management(r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets2")
arcpy.env.workspace = r'J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb'
table1 = r"street_assets"
field1 = r"STREET_OR_INTERSECTION"
def unique_values(table, field):
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})
newtuple = unique_values(table1,field1)
newtuple = str(newtuple)
newtuple = newtuple.split("}{")
newtuple = ([s.replace('\'', '') for s in newtuple])
newtuple = ([s.replace('"', '') for s in newtuple])
newtuple = ([s.replace('u', '') for s in newtuple])
newtuple = ([s.replace('[', '') for s in newtuple])
newtuple = ([s.replace(']', '') for s in newtuple])
newtuple = ([s.replace('{', '') for s in newtuple])
newtuple = ([s.replace('}', '') for s in newtuple])
out_path = r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb"
out_name = "street_assets2"
geometry_type = "POINT"
template = r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets"
has_m = "DISABLED"
has_z = "DISABLED"
spatial_reference = arcpy.Describe(r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets").spatialReference
arcpy.CreateFeatureclass_management(out_path, out_name, geometry_type, template, has_m, has_z, spatial_reference)
newtuple = tuple(newtuple)
print newtuple

## Problem Here


cursor = arcpy.da.InsertCursor(r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets2", ['STREET_OR_INTERSECTION'])
i = 0
for i in newtuple:
    cursor.insertRow([i])
    i = i + 1
1

When working with cursors, each row is a tuple. In your case, you need to create a tuple with one value.

cursor = arcpy.da.InsertCursor(r"J:\STW\Divisions_&_Branches\MSMD\Branches_&_Sections\GIS\users\Anault\intersections_software_development\OUTPUT.gdb\street_assets2", ['STREET_OR_INTERSECTION'])
for i in newtuple:
    #create tuple with one value
    row = (i,)
    cursor.insertRow(row)
del cursor

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.