如何使用 dbf 模块更新 dbf 中的记录:https://pypi.python.org/pypi/dbf
这是我尝试过的:
table2 = dbf.Table(filename, codepage="cp1252")
table[0].name = "changed"
但是我得到:
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()`
我设法读取和追加但不能修改数据,我该怎么做?
请您参考如下方法:
可以通过几种不同的方式将数据写入记录:
使用记录作为上下文管理器:
以表 [0] 作为记录: rec.name = "已更改"使用
dbf.Process函数循环处理多个记录:在进程中记录(my_table): rec.name = rec.name.title()使用
dbf模块中的write函数:dbf.write(some_record, name='我的新名字')
我这样做是为了提高安全性和性能。
