Is there a way I can create a list of only the deletable fields in a feature class (and by deletable I mean fields other than OBJECTID, Shape, etc . I tried using arcpy.ListFields(), but it list all of the feilds.
You will have to filter your list of fields produced by arcpy.ListFields() using the properties of the Field object. If you need help on filtering your list, the Dive Into Python guide has an excellent chapter on this: 4.5. Filtering Lists.
List comprehensions are just so elegant.
efields = [f.name for f in arcpy.ListFields(table) if f.editable]
I just used:
for i in range(len(parcelFieldList)): if parcelFieldList.editable: parcelFieldNames.append(str(parcelFieldList.name))
just be aware of the subtle difference between editable and required
...
Editable fields:
[[False, u'FID'], [True, u'Shape'], [True, u'Id'], [True, u'X'], [True, u'Y'], [True, u'Label']]
Required fields:
[[True, u'FID'], [True, u'Shape'], [False, u'Id'], [False, u'X'], [False, u'Y'], [False, u'Label']]
Thanks for your quick reply! From your post, I realized that I could use the editable method to check to see if a field can be deleted or not!
like this...
>>> import arcpy >>> shp_file = "c:/temp/x.shp" >>> flds = arcpy.ListFields(shp_file) >>> >>> req_flds = [ [fld.required, fld.name] for fld in flds] >>> req_flds [[True, u'FID'], [True, u'Shape'], [False, u'Id'], [False, u'X'], [False, u'Y'], [False, u'Label']] >>>
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.