Hi all,
I am currently writing a script that is looping through all geodatabases under a specific folder. It will find a field called INSTLN_ID, and compare all entries against a list of acceptable INSTLN_ID entries. I have this code running perfectly fine for one Geodatabase, but it throws an error when I add a second one. This script is reused from another script (that checks for duplicates in a different field), and it works fine. For some reason, when i changed it to find the wrong entries for INSTLN_ID it throws "RuntimeError: ERROR 999999; Error executing funtion.
I was wondering if anyone can find error in my code. I am a novice, so I understand I can shorten code, etc. I am looking for a resolution to the error message, though.
Thanks in advance!
here is the code:
I am currently writing a script that is looping through all geodatabases under a specific folder. It will find a field called INSTLN_ID, and compare all entries against a list of acceptable INSTLN_ID entries. I have this code running perfectly fine for one Geodatabase, but it throws an error when I add a second one. This script is reused from another script (that checks for duplicates in a different field), and it works fine. For some reason, when i changed it to find the wrong entries for INSTLN_ID it throws "RuntimeError: ERROR 999999; Error executing funtion.
I was wondering if anyone can find error in my code. I am a novice, so I understand I can shorten code, etc. I am looking for a resolution to the error message, though.
Thanks in advance!
here is the code:
Code:
import arcpy, os
from arcpy import env
folder = r"C:\\Users\\skillingd\\Documents\\3.0Python"
#folder=(raw_input("Please enter the path to the folder where all of your .mdb's are located."))
for (path, dirs, files) in os.walk(folder):
if ".mdb" not in path.lower():
env.workspace = path
databases = arcpy.ListWorkspaces("*", "Access")
#print databases
for database in databases:
#print database
env.workspace=database
featuredataset=arcpy.ListDatasets("*", "Feature")
#print featuredataset
for fd in featuredataset:
print "working on", fd, "dataset."
fc=arcpy.ListFeatureClasses("*", "All", fd)
#print fc
for fclass in fc:
print "working on",fclass,"feature class."
searchCurs=arcpy.SearchCursor(fclass)
row=searchCurs.next()
ValueList=list()
while row:
pk=row.getValue("INSTLN_ID")
row=searchCurs.next()
#pk=int(pk)
#print type(pk)
ValueList.append(str(pk))
#print ValueList
ids=set(["N61152", "N61152-AN", "N61152-BA", "N61152-SV", "N61152-CB", "N32414-BA", "N61151", "N61151-PN", "N61151-IH", "N61151-SN", "N68469", "N68469-MI", "N68469-NR", "N68469-NO", "N684-AE", "N68469-DA", "N68469-CR", "N61142-AN","N33355", "N47608", "N47608-WF", "N47608-SI", "N47608-HA", "N47608-BI", "N47608-TM", "N47608-BA", "N47608-EA", "N47608-WO", "N47608-MA", "N47608-KA", "N47608-DA", "N47608-CA", "N47608-LA", "N47608-TR"])
seen=set()
seen_add=seen.add
not_correct = set( x for x in ValueList if x not in ids)
wrong=list(not_correct)
## print "These records are not correct", wrong
if not wrong:
print "All INSTLN_ID's are correct"
else:
print "Your incorrect INSTLN_ID's are from",fclass, "and the values are:" , list (wrong)
with open("WrongINSTLN_ID's.txt", "a") as text_file:
text_file.writelines("Geodatabase Location/Name:")
text_file.writelines(str(database)+"\n")
text_file.writelines("Feature Dataset:")
text_file.writelines(str(fd)+"\n")
text_file.writelines("Feature Class:")
text_file.writelines(str(fclass)+ "\n")
text_file.writelines("Incorrect INSTLN_ID netries:"+ "\n")
for l in wrong:
text_file.writelines(str(l)+"\n")
text_file.writelines("__________________________________________________________________________________________________________________"+"\n")