I have a shapefile containing fields of float type of which I have exported to a file geodatabase. I would like to list only the fields of float type in the resultant feature class but float isn't an option and gives an empty list.
[f.name for f in arcpy.ListFields("Test") if f.type == 'Float']
[]
Double is fine of course.
[f.name for f in arcpy.ListFields("Test") if f.type == 'Double']
['H10_iso', 'H12_iso', 'H15_iso', 'H16_iso', 'H17_iso', 'H18_iso', 'H20_iso']
Would I need to create fields of double type in the feature class and update the values or is there another way?
Solved! Go to Solution.
Float fields are listed as Single:
table = arcpy.management.CreateTable("memory", "bla")
arcpy.management.AddField(table, "FloatField", "FLOAT")
arcpy.management.AddField(table, "DoubleField", "DOUBLE")
for f in arcpy.ListFields(table):
print(f.name, f.type)
#OBJECTID OID
#FloatField Single
#DoubleField Double
Float fields are listed as Single:
table = arcpy.management.CreateTable("memory", "bla")
arcpy.management.AddField(table, "FloatField", "FLOAT")
arcpy.management.AddField(table, "DoubleField", "DOUBLE")
for f in arcpy.ListFields(table):
print(f.name, f.type)
#OBJECTID OID
#FloatField Single
#DoubleField Double
You could also specify the type you want directly in ListFields using field_type.
https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm
https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/field.htm
table = arcpy.management.CreateTable("memory", "bla")
arcpy.management.AddField(table, "FloatField", "FLOAT")
arcpy.management.AddField(table, "DoubleField", "DOUBLE")
for f in arcpy.ListFields(table, field_type="Single"):
print(f.name, f.type)
#FloatField Single