使用Python脚本进行图层的重命名拷贝及删除,并在过程中利用logging进行日志记录。
附上Python代码:
1 # -*- coding: utf-8 -*- 2 # nightroad 3 import sys 4 import arcpy 5 import logging 6 7 logging.basicConfig(level=logging.DEBUG, 8 format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', 9 datefmt='%a, %d %b %Y %H:%M:%S', 10 filename='log.txt', 11 filemode='a') 12 path = r"C:Users ightroadAppDataRoamingESRIDesktop10.0ArcCatalog est.sdeTEST" 13 arcpy.env.workspace = path 14 try: 15 print "delete line_1" 16 logging.info("delete line_1") 17 arcpy.Delete_management("line_1") 18 print "delete point_1" 19 logging.info("delete point_1") 20 arcpy.Delete_management("point_1") 21 except Exception as e: 22 print("no data or delete error!",e) 23 logging.warning("no data or delete error!") 24 try: 25 print "rename line" 26 logging.info("rename line") 27 arcpy.Rename_management("line", "line_1") 28 print "rename point" 29 logging.info("rename point") 30 arcpy.Rename_management("point", "point_1") 31 try: 32 print "copy point" 33 logging.info("copy point") 34 arcpy.Copy_management(r"E:TEST.gdbTESTpoint","point") 35 print "copy line" 36 logging.info("copy line") 37 arcpy.Copy_management(r"E:TEST.gdbTESTline","line") 38 try: 39 print "delete line_1" 40 logging.info("delete line_1") 41 arcpy.Delete_management("line_1") 42 print "delete point_1" 43 logging.info("delete point_1") 44 arcpy.Delete_management("point_1") 45 except Exception as e: 46 print("delete error!",e) 47 logging.error("delete error!") 48 except Exception as e: 49 print("copy error!",e) 50 logging.error("copy error!") 51 except Exception as e: 52 print("rename error!",e) 53 logging.error("rename error!")