Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Archives Historic SAP Numbers
- import arcpy
- fc = "U:/Data/Leases.gdb/LeasePlans"
- changes = "U:/Data/To_be_Deleted.csv"
- #New Field Criteria
- field_Name = "Status"
- field_Nametype = "Text"
- field_NameVal = arcpy.ValidateFieldName(field_Name)
- #Adds the new field if it doesn't already exist
- fList = arcpy.ListFields(fc,field_Name)
- if not fList:
- arcpy.AddField_management(fc, field_Name, field_Nametype, "", "", "")
- #List comprehension for IDs
- ids = [i for i, in arcpy.da.SearchCursor
- (changes, "SAPNO") if i != None]
- Relevant_Fields = ['Property_Ref', 'Status']
- #update cursor to Insert 'Archived' rows
- with arcpy.da.UpdateCursor (fc, Relevant_Fields) as cursor:
- for SAPNO, in cursor:
- if SAPNO in ids:
- row[1] = 'Archived'
- cursor.UpdateRow()
- del cursor
- import arcpy, csv
- fc = r'C:database.gdbfeature_class'
- codefile = r"C:folderfile.csv"
- with open(codefile, 'r') as f:
- reader = csv.reader(f)
- sapno_list = [k for k in reader]
- fc_fields = ['Property_Ref','Status']
- with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
- for row in cursor:
- if row[0] in sapno_list:
- row[1]='Archived'
- cursor.updateRow(row)
- else:
- print "Did not find value for Propetry_Ref: {0}".format(row[0])
Add Comment
Please, Sign In to add comment