Wondering how I can edit individual values using Ethan Furman's dbf library. I can edit the fields using
with dbf.Table(insertPreviouslyAssignedValueHere) as table:
for record in dbf.Process(table):
record[field] = desiredValue
but this edits an entire column to be the same value. I need a way to edit values anywhere in the file individually as well as add new rows to edit. I've tried reading over some old documentation here but I can't find a function for editing individual cells. I can also peek at an individual value though
table[column][row]
But still, no editing feature in this fashion.
CodePudding user response:
A record is also a context manager, so:
with table[column][row] as rec:
rec.some_field = 77
will work. The advantage of doing it this way is that if you are updating multiple fields, and one of the assignments raises an exception, the record is not updated and so not in an inconsistent state.