Error in Empty Field Length

532
6
Jump to solution
12-28-2023 03:25 AM
Krishna_94
New Contributor II

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?

Krishna_94_0-1703762346253.png

 

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!!

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

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 ""} ')

 

View solution in original post

Tags (3)
6 Replies
chagade6
New Contributor

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/ .

0 Kudos
Krishna_94
New Contributor II

@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!

Krishna_94_1-1703839913088.png

 

 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

Krishna_94
New Contributor II

@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.

Krishna_94_0-1703839529418.png

 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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 ""} ')

 

Tags (3)
Krishna_94
New Contributor II

Thank you for the suggestion @JoshuaBixby .

0 Kudos