arcpy.TableToTable_conversion("Test","C:\\TestData","Test.dbf",,(["City"],["Zip"]))
Solved! Go to Solution.
I have about ten fields but only want to export the City and Zip fields into the new Test.dbf file. I can get it to write all the fields to the new dbf file but am struggling with exporting just two.
arcpy.CreateTable_management(arcpy.env.workspace,"out.dbf") arcpy.AddField_management("out.dbf","City","Text",field_length=20) arcpy.AddField_management("out.dbf","Zip","text",field_length=9) arcpy.DeleteField_management("out.dbf","ID") # dummy field created by CreateTable arcpy.Append_management("in_table","out.dbf","NO_TEST")
I have about ten fields but only want to export the City and Zip fields into the new Test.dbf file. I can get it to write all the fields to the new dbf file but am struggling with exporting just two.
arcpy.CreateTable_management(arcpy.env.workspace,"out.dbf") arcpy.AddField_management("out.dbf","City","Text",field_length=20) arcpy.AddField_management("out.dbf","Zip","text",field_length=9) arcpy.DeleteField_management("out.dbf","ID") # dummy field created by CreateTable arcpy.Append_management("in_table","out.dbf","NO_TEST")
You could futz with the fieldmappings object (you can look that up in the help), but honestly the easiest way to do what you want is to create the output table with just the two fields you want, and use Append_management with the "NO_TEST" option to copy the two fields over. The fields that do not match (by name) will be ignored in the append.arcpy.CreateTable_management(arcpy.env.workspace,"out.dbf") arcpy.AddField_management("out.dbf","City","Text",field_length=20) arcpy.AddField_management("out.dbf","Zip","text",field_length=9) arcpy.DeleteField_management("out.dbf","ID") # dummy field created by CreateTable arcpy.Append_management("in_table","out.dbf","NO_TEST")