使用Python脚本进行图层的重命名拷贝及删除,并在过程中利用logging进行日志记录。

附上Python代码:

 # -*- coding: utf-8 -*-
# nightroad
import sys
import arcpy
import logging logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='log.txt',
filemode='a')
path = r"C:\Users\nightroad\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\test.sde\TEST"
arcpy.env.workspace = path
try:
print "delete line_1"
logging.info("delete line_1")
arcpy.Delete_management("line_1")
print "delete point_1"
logging.info("delete point_1")
arcpy.Delete_management("point_1")
except Exception as e:
print("no data or delete error!",e)
logging.warning("no data or delete error!")
try:
print "rename line"
logging.info("rename line")
arcpy.Rename_management("line", "line_1")
print "rename point"
logging.info("rename point")
arcpy.Rename_management("point", "point_1")
try:
print "copy point"
logging.info("copy point")
arcpy.Copy_management(r"E:\TEST.gdb\TEST\point","point")
print "copy line"
logging.info("copy line")
arcpy.Copy_management(r"E:\TEST.gdb\TEST\line","line")
try:
print "delete line_1"
logging.info("delete line_1")
arcpy.Delete_management("line_1")
print "delete point_1"
logging.info("delete point_1")
arcpy.Delete_management("point_1")
except Exception as e:
print("delete error!",e)
logging.error("delete error!")
except Exception as e:
print("copy error!",e)
logging.error("copy error!")
except Exception as e:
print("rename error!",e)
logging.error("rename error!")
05-11 22:16