Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to figure out if it is possible to rename a field with the current date. What I am trying to accomplish is a table to table conversion, dropping a dozen fields, leaving only two fields, Name and Status. I want the Status field to be renamed to Status_yyyy_mm_dd. The script will then run a join field to another table, thus creating a history of the status field by day. I am running Arc 10.1. I have everything working, except the naming bit. Any help would be greatly appreciated.

import arcpy
import time

uiq = "uiq_data_set"
gdb = "c:\\Temp\\default1.gdb"
newFieldName = "Status_" + time.strftime('%Y_%m_%d')

arcpy.TableToTable_conversion(uiq, gdb, "uiq_historic", "", "Name \"Name\" true true false 255 Text 0 0 ,First,#,c:\\Temp\\default1.gdb\\uiq_data_set,Name,-1,-1;Status\"Status\" true true false 255 Text 0 0 ,First,#,c:\\Temp\\default1.gdb\\uiq_data_set,Status,-1,-1", "")
share|improve this question
    
Solution that I ended up using: arcpy.TableToTable_conversion(uiq, gdb, "uiq_historic", "", "{0} \"{0}\" true .......,-1,-1".format(newfieldName),"") –  user20852 Aug 9 '13 at 13:55
add comment

2 Answers 2

You can't rename the field. An alternative to field_mappings described in Curtis' answer is to create a new field with the desired name and copy the values across (possibly deleting the old field to save data bloat). This is a simple and permanent solution.

share|improve this answer
    
In a table to table you can rename the field. For example, Name is called three times in the script. The first and second are the field name and alias for the field in the new table, and the third is the field that is being copied from the original table. If I change the first two instances of Name to Renamed, the field in the new table will be called Renamed, with an alias of Renamed. Same effect as when you use the tool in ArcMap and right click on a field name in Field Mapping, and either rename or go to properties to set the name and alias. –  user20852 Aug 8 '13 at 11:48
add comment

I believe the best way to accomplish this is create a FieldMappings object and use it with the TableToTable or Merge tool to copy the table.

You're working with the string representation, which very cumbersome to work with. FieldMappings are a bit complicated but once you get the hang of them they are very useful.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.