3

I would like to rename a feature class based on the EDITOR and DATE fields. I wrote this code:

    import arcpy

fc = "C:\Users\PythonTesting.gdb\MyFile"
f1, f2, f3 = "EDITOR", "DATE", "OBJECTID"
clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1"
for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)):
     print ("{0}_{1}".format(row[0], row[1]))

And it works great, prints out the one line of results I want. But now I can't figure out how to use those results as the output for a rename. I have used the rename before but with out such an expression.

I checked out this one thinking it would help but I still can't figure it out. How to rename feature classes based on field values within the attribute table?

4

Figured it out. Boy that was easy!

>>> import arcpy
... 
... fc = "C:\Users\PythonTesting.gdb\My_File"
... f1, f2, f3 = "EDITOR", "COUNTY", "OBJECTID"
... clause = arcpy.AddFieldDelimiters(fc, f3) + "= 1"
... for row in sorted (arcpy.da.SearchCursor (fc, [f1, f2], clause)):
...     print ("{0}_{1}".format(row[0], row[1]))
...     name =("{0}_{1}".format(row[0], row[1]))
...     arcpy.Rename_management(fc, name)

My major problem was the way the date is formatted. But knowing that this function works is good, now I just need to fix the date.

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.