ArcGIS Pro 3.1 (also same error tested on 2.9)
Getting an AttributeError when using arcpy.AddMessage() to print the default values for fields.
AttributeError: Object: Error in parsing arguments for AddMessage
Original code...
import arcpy
## path to feature class
fc = r"C:\Path\To\GDB\FeatureClass"
## describe the data and return a dictionary
desc = arcpy.da.Describe(fc)
## for each field object in the fields property
for field_obj in desc["fields"]:
## print the field name
arcpy.AddMessage(field_obj.name)
## print the field defaultValue
arcpy.AddMessage(field_obj.defaultValue)
Solved! Go to Solution.
Figured it out shortly after original post.
ArcPy does not like a None value as input parameter for the AddMessage() function, replaced with string formatting below.
import arcpy
## path to feature class
fc = r"C:\Path\To\GDB\FeatureClass"
## describe the data and return a dictionary
desc = arcpy.da.Describe(fc)
## for each field object in the fields property
for field_obj in desc["fields"]:
## print the field name
arcpy.AddMessage(field_obj.name)
## print the field defaultValue
arcpy.AddMessage("{0}".format(field_obj.defaultValue))
The defaultValue property was returning None for some fields. If you run the below it will throw the AttributeError, seen in original post, showing that the input to the AddMessage function must be convertible to a string.
## AttributeError
arcpy.AddMessage(None)
Figured it out shortly after original post.
ArcPy does not like a None value as input parameter for the AddMessage() function, replaced with string formatting below.
import arcpy
## path to feature class
fc = r"C:\Path\To\GDB\FeatureClass"
## describe the data and return a dictionary
desc = arcpy.da.Describe(fc)
## for each field object in the fields property
for field_obj in desc["fields"]:
## print the field name
arcpy.AddMessage(field_obj.name)
## print the field defaultValue
arcpy.AddMessage("{0}".format(field_obj.defaultValue))
The defaultValue property was returning None for some fields. If you run the below it will throw the AttributeError, seen in original post, showing that the input to the AddMessage function must be convertible to a string.
## AttributeError
arcpy.AddMessage(None)