How can I update a record in a dbf with the dbf module : https://pypi.python.org/pypi/dbf
Here is what I tried:
table2 = dbf.Table(filename, codepage="cp1252")
table[0].name = "changed"
But I get:
File "<input>", line 1, in <module>
File "/venv/lib/python3.4/site-packages/dbf/ver_33.py", line 2508, in __setattr__
raise DbfError("unable to modify fields individually except in `with` or `Process()`")
dbf.ver_33.DbfError: unable to modify fields individually except in `with` or `Process()`
I managed to read and append but not to modify data, how can I do that?
Writing data to records can be accomplished in a few different ways:
using the record as a context manager:
with table[0] as rec:
rec.name = "changed"
using the dbf.Process
function to deal with several records in a loop:
for rec in Process(my_table):
rec.name = rec.name.title()
using the write
function in the dbf
module:
dbf.write(some_record, name='My New Name')
I did it this way to enhance both safety and performance.