3

Is there any way to use a cursor to delete a field using ArcPy?

I understand there are ways to use a cursor to delete records but I'm looking for a way to delete a field using a cursor.

  • 1
    To delete a field you want arcpy.DeleteField_management resources.arcgis.com/en/help/main/10.2/index.html#//… but you can't do that with an active cursor because it locks the table. – Michael Stimson Dec 16 '19 at 1:30
  • @MichaelStimson I know that arcpy.DeleteField_management is an option but I was wondering if there is a way to achieve the same result with a cursor – Emma Pascoe Dec 16 '19 at 1:33
  • @SonofaBeach I'm looking to delete the field from the table all together – Emma Pascoe Dec 16 '19 at 1:33
5

No. You cannot use a cursor to delete a field from the schema of a table or feature class.

Cursors are used to view or edit data, not to alter the schema.

As @MichalStimson commented, you will need to use arcpy.DeleteField_management() to delete a field, and this cannot be done while there is an active cursor due to the cursor's lock on the table.

See: Search Cursor, Update Cursor, Delete Field

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.