I've got back into Python after a long break. I'm creating a simple data validation script at the moment. I am just trying to return the field type of a field input by the user. I'm using arcpy.AddMessage to validate my steps as I go along. I've tried googling and looking at multiple questions on here and have found nothing that works. Here is my code:

gulyShp = arcpy.GetParameterAsText (0)
sDep = arcpy.GetParameterAsText (1)


sDTy = arcpy.Field(sDep.Type)

All I want is the type of the field sDep is assigned to be stored in a variable.


Try ListFields to list field objects which has properties like type and name:

sDTy = [f.type for f in arcpy.ListFields(gulyShp) if f.name == sDep][0]

gulyShp need to be a complete path and filename, or only the filename and arcpy.env.workspace set to the shapefile folder.

I am using Listfield with list comprehension. The [0] is to fetch first (and in this case only) item in the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.