In ArcGIS Pro I have a feature class called SWNDMNHL which has the list of fields, in which some fields have empty length, but when I'm fetching this fields from Python arcpy library it gives me a random field length instead of empty field length. How should i validate the field length?
for fld in arcpy.ListFields('SWNDMNHL'):
print(f'Field : {str(fld.name)} and Length : {str(fld.length)} ')
It gives me below output:
Field : COVER_LVL and Length : 8, Field : COV_SLB_LVL and Length : 8, Field : COV_THKNS and Length : 2
Any suggestions?
Thank you!!
Solved! Go to Solution.
I don't believe the fieldDescription class is exposed through ArcPy, or at least the Length property you are looking for under fieldDescription. That said, you don't need it to be since you can simply check the field type and return an empty string if it is anything but Text. Something like:
for fld in arcpy.ListFields('SWNDMNHL'):
print(f'Field : {fld.name} and Length : {fld.length if fld.type == "String" else ""} ')
It depends a little bit. Is there any field that is filled in every note? If so, the easiest thing to do is change your order of fields & make that field #1 https://routerlogin.uno/ .
@chagade6 Thank you for the suggestion, but I'm not getting your answer, like how can I get empty Field Length based on order of Field!?
Using ArcPy Module I'm getting the Length of Field using ListFields() Method, as you can see in screenshot Field Length is Empty but I'm not getting empty length, For Short getting 2 as Field Length and for Double getting 4 as Field Length instead of this, I want Empty Fields to Validate!
The two lengths you are looking at are not measuring the same "length." Although Esri doesn't clearly state it, the behavior you are seeing can be explained by the Fields view in the ArcGIS Pro GUI displaying FieldDescription Class—ArcGIS Pro length while the ArcPy Field object is giving you Field Class—ArcGIS Pro length. The FieldDescription Class length only applies to String and OID fields, so it shows nothing/empty for numeric data types, while the Field Class length applies to all fields.
@JoshuaBixby Thank you for the suggestion, I still don't get the solution can you suggest me how to access Field Description Class using ArcPy Module? I have been searching for the method for ArcPy module and I can find only ListFields() Method to get Field Length.
I want the Fields which doesn't have length but with ListFields() I'm getting default value like for instance if the Field type is Short then it will return Field Length 2 but as you can see in provided Screenshot, I do not assign any Field Length to that attribute.
I don't believe the fieldDescription class is exposed through ArcPy, or at least the Length property you are looking for under fieldDescription. That said, you don't need it to be since you can simply check the field type and return an empty string if it is anything but Text. Something like:
for fld in arcpy.ListFields('SWNDMNHL'):
print(f'Field : {fld.name} and Length : {fld.length if fld.type == "String" else ""} ')
Thank you for the suggestion @JoshuaBixby .