我正在尝试使用 python 2.7 和 dbf 包在可视 Foxpro 6 dbf 文件中写入/删除记录:
import dbf
tbl = dbf.Table('test.dbf')
tbl.open()
rec = tbl[0]
print(rec.__class__)
rec.delete_record()
结果:
<class 'dbf.ver_2.Record'>
Traceback (most recent call last):
File "C:/Python/Projects/test/test.py", line 11, in <module>
rec.delete_record()
File "C:\Python\Projects\test\venv\lib\site-packages\dbf\ver_2.py", line 2503, in __getattr__
raise FieldMissingError(name)
dbf.ver_2.FieldMissingError: 'delete_record: no such field in table'
这是该包的文档:http : //pythonhosted.org/dbf/
记录对象确实没有这个方法,但它被记录在案。该表以读写模式打开。(但 Table() 构造函数也应该返回一个打开的表,但它返回的是一个关闭的表。)
我究竟做错了什么?
最大的问题是没有其他选择。我知道的唯一其他包是“dbfpy”,但它不处理 vfoxpro 6 表,也不处理不同的字符编码。
该文档已过时。(我很抱歉。)
你想要的是:
dbf.delete(rec)
tbl.pack()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句