List fields of 'Float' type in a feature class using arcpy.ListFields()

448
2
Jump to solution
09-21-2022 01:10 AM
MattHowe
Occasional Contributor

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?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

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

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

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

Have a great day!
Johannes
SamSzotkowski
New Contributor III

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