[arcpy] Get field information of the table in GDB

You can use the ListFields function in arcpy to obtain the field information of the table in GDB, including name, length and type. The sample code is as follows:

import arcpy

# 设置工作空间
arcpy.env.workspace = r"C:\data\myGDB.gdb"

# 获取表名
table_name = "myTable"

# 获取字段列表
fields = arcpy.ListFields(table_name)

# 遍历字段列表,输出字段名称、长度和类型
for field in fields:
    print("Field Name: {}".format(field.name))
    print("Field Length: {}".format(field.length))
    print("Field Type: {}".format(field.type))

Among them, arcpy.ListFields(table_name)the function returns a list of field objects, and the name, length, type and other information of each field can be obtained by traversing the list.

Guess you like

Origin blog.csdn.net/weixin_43958438/article/details/130743757