arcpy 读写csv_字段属性输出到csv文档

 

# coding=gbk
import csv
import arcpy


def main():
    # 读取
    # csv_path=r"E:\2 learning\course\arcpy进阶\arcpy\4 文本读写\csv\test.csv"
    # csv_file=open(csv_path,'r')
    # csv_reader=csv.reader(csv_file)
    # csv_reader.next()
    # for line in csv_reader:
    #     print line[1].decode('gbk')
    # csv_file.close()

    # 字段属性写入csv
    fc_path=r'E:\2 learning\course\arcpy进阶\arcpy\0 基础\数据访问\data.mdb\test'
    csv_path_out=r"E:\2 learning\course\arcpy进阶\arcpy\4 文本读写\csv\fields.csv"
    csv_file_out=open(csv_path_out,'wb')
    csv_writer=csv.writer(csv_file_out)
    title=['字段名','别名','类型','长度','精度','小数位数']
    csv_writer.writerow(title)
    fields=arcpy.ListFields(fc_path)
    for field in fields:
        csv_writer.writerow([
            field.name.encode('gbk'),
            field.aliasName.encode('gbk'),
            field.type.encode('gbk'),
            field.length,
            field.precision,
            field.scale
        ])
    csv_file_out.close()



if __name__ == '__main__':
    main()

 

posted @ 2021-02-15 19:39  yzhyingcool  阅读(765)  评论(0编辑  收藏  举报