ListSubtypes

Resumen

Returns a dictionary of the subtypes for a table or feature class.

Debate

Only use the ListSubtypes function when there is a subtype field set on the table or feature class. If there is no subtype field set in the input, a dictionary will be returned with a single subtype key of 0 (in addition, the Default key value will be True, the Name key value will be the name of the feature class or table, and the SubtypeField key value will be an empty string). Use the Set Subtype Field tool to define the field that stores subtype codes.

Sintaxis

ListSubtypes (table)
ParámetroExplicaciónTipo de datos
table

The geodatabase table or feature class.

String
Valor de retorno
Tipo de datosExplicación
Dictionary

Returns a dictionary of subtype properties. The keys of the dictionary are the subtype codes, and the values of the dictionary are the subtype properties.

Muestra de código

ListSubtypes example

List all the subtypes for a feature class and print the properties for each one.

import arcpy

subtypes = arcpy.da.ListSubtypes("C:/data/Boston.gdb/Boundary")

for stcode, stdict in list(subtypes.items()):
    print(f"Code: {stcode}")
    for stkey in list(stdict.keys()):
        if stkey == "FieldValues":
            print("Fields:")
            fields = stdict[stkey]
            for field, fieldvals in list(fields.items()):
                print(f" --Field name: {field}")
                print(f" --Field default value: {fieldvals[0]}")
                if not fieldvals[1] is None:
                    print(f" --Domain name: {fieldvals[1].name}")
        else:
            print(f"{stkey}: {stdict[stkey]}")