Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #Archives Historic SAP Numbers
  2. import arcpy
  3.  
  4. fc = "U:/Data/Leases.gdb/LeasePlans"
  5. changes = "U:/Data/To_be_Deleted.csv"
  6.  
  7. #New Field Criteria
  8. field_Name = "Status"
  9. field_Nametype = "Text"
  10. field_NameVal = arcpy.ValidateFieldName(field_Name)
  11.  
  12. #Adds the new field if it doesn't already exist
  13. fList = arcpy.ListFields(fc,field_Name)
  14. if not fList:
  15. arcpy.AddField_management(fc, field_Name, field_Nametype, "", "", "")
  16.  
  17. #List comprehension for IDs
  18. ids = [i for i, in arcpy.da.SearchCursor
  19. (changes, "SAPNO") if i != None]
  20.  
  21.  
  22. Relevant_Fields = ['Property_Ref', 'Status']
  23.  
  24. #update cursor to Insert 'Archived' rows
  25. with arcpy.da.UpdateCursor (fc, Relevant_Fields) as cursor:
  26. for SAPNO, in cursor:
  27. if SAPNO in ids:
  28. row[1] = 'Archived'
  29. cursor.UpdateRow()
  30.  
  31. del cursor
Add Comment
Please, Sign In to add comment