How to check of a field exists in arcpy.FieldMappings

975
2
05-08-2017 09:21 AM
JoseSanchez
Occasional Contributor III

Hello everyone,

Is there a way to check if a field exits in a arcpy.FieldMappings

fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(fc1)
fieldmappings.addTable(fc2)

if fieldmappings.findFieldMapIndex("SHAPE_LEN")   ??????  how to check that this field exists to remove it?
  print"not found"

0 Kudos
2 Replies
KaushikMysorekar
New Contributor III

One way of doing it is:

fldIdx = fieldmappings.findFieldMapIndex("<field>")
if fldIdx > -1:
    fieldmappings.removeFieldMap(fldIdx)‍‍‍‍‍‍‍‍‍‍
JoshuaBixby
MVP Esteemed Contributor

For future reference, this appears to be an ArcPy question, not an ArcGIS API for Python question.  The https://community.esri.com/community/developers/gis-developers/python?sr=search&searchId=6b7dbc24-80...‌ space is a higher-visibility area for ArcPy-related questions.

https://community.esri.com/docs/DOC-1544-geonet-community-structure?sr=search&searchId=cc7f9fc1-bd8e...

0 Kudos