To convert our save_record() method so that we can update records, the first thing we'll need to do is provide the ability to pass in a row number to update. The default will be None, which will indicate that the data is a new row that should be appended.
The new method signature looks like this:
def save_record(self, data, rownum=None): """Save a dict of data to the CSV file"""
Our existing logic doesn't need to change, but it should only be run if rownum is None.
So, the first thing to do in the method is check rownum:
if rownum is not None: # This is an update, new code here else: # Old code goes here, indented one more level
For relatively small files, the simplest way to update a single row is to load ...