#I would really appreciate some help on this: I need to use the Set function on this script to remove all
# my duplicates but the InsertCursor refuses to work here. Any Ideas, Thank You- Larry Adgate
import arcpy
fc1 = "Database Connections\\TaskmasterServer.sde\\sde_gsw.GSW_SDE.CCB_Updates1"
fc2= "Database Connections\\TaskmasterServer.sde\\sde_gsw.GSW_SDE.CCB_Data\\sde_gsw.GSW_SDE.Master_CCB_Points"
fc3 = "K:\\808 - TariffMaps\\MyResults\\MyTable.dbf"
set_one = set(r[0] for r in arcpy.da.SearchCursor(fc1,"PREM_ID"))
set_two = set(r[0] for r in arcpy.da.SearchCursor(fc2,"PREM_ID"))
print "Items unique to the Primary Field: {}".format(", ".join(sorted(set_one-set_two)))
results = set(set_one-set_two)
print results
cursor = arcpy.da.InsertCursor(fc3, ["result"])
#Below is my error= TypeError: value #0 - unsupported type: set
cursor.insertRow([results])
del cursor
Solved! Go to Solution.
What about:
cursor = arcpy.da.InsertCursor(fc3, ["result"])
for i in results:
cursor.insertRow([i])
del cursor
In the geodatabase, what data type is the "result" field in for fc3? You can't store Python data structures likes lists, tuples, sets, dictionaries, etc... directly in a record in a geodatabase, so I am trying to understand what data type "result" is since the field is already created.
Hi Joshuba,
My result data structure are numbers in a text field: Ex: 0000256677
My numbers have leading zeros so the field needs to be text
Thank You,
Larry
what does one of your sets look like? Something like set(000025667, 000026443, ....)? If so, how do you want that to look in the text field in the geodatabase?
You can cast the result to string before writing the result using something similar as you already did with:
", ".join(sorted(set_one-set_two))
(this may generate too many characters to be contained in the field), but I don't understand the purpose of what you are trying to do. Every record will have a string representing the list of ID's that are in fc1 but not in fc2. When you have that, what will you do with this result?
A A Typical set is in a text Field column. called PREM_ID-
What about:
cursor = arcpy.da.InsertCursor(fc3, ["result"])
for i in results:
cursor.insertRow([i])
del cursor
Thank You so Much........it Works
Larry
You inadvertently marked your answer as correct, I unmarked it, please go back and mark the correct response as being the one