Tuesday, 23 February 2016

arcpy - How to truncate file geodatabase tables with Python?



I need to truncate file geodatabase tables (1 or all) with Python. What is the code for that?



Answer



AFAIK, you can use Delete Rows method in arcpy. from Arcgis Resource Center:


Delete Rows (Data Management)



Summary


Deletes all or the selected subset of rows from the input.


If the input rows are from a feature class or table, all rows will be deleted. If the input rows are from a layer or table view with no selection, all rows will be deleted.



consider this caution:




If run against a layer or table view that does not have a selection, the operation cannot be undone using undo/redo.



Example Code:


import arcpy
from arcpy import env

env.workspace = "C:/data"
arcpy.CopyRows_management("accident.dbf", "C:/output/accident2.dbf")
arcpy.DeleteRows_management("C:/output/accident2.dbf")


i hope it helps you...


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...