尝试使用我的dbf
图书馆:
import dbf
table = dbf.Table('file.DBF')
打印它以查看文件中是否存在编码:
print table # print(table) in Python 3
我的测试表之一如下所示:
Table: tempy.dbf
Type: dBase III Plus
Codepage: ascii (plain ol ascii)
Status: DbfStatus.CLOSED
Last updated: 2019-07-26
Record count: 1
Field count: 2
Record length: 31
--Fields--
0) name C(20)
1) desc M
重要的是该Codepage
行-听起来好像DBF
文件没有正确设置。如果知道应该是什么,则可以使用以下代码页(临时)打开它:
table = dbf.Table('file.DBF', codepage='...')
或者,您可以使用以下命令永久更改(更新DBF
文件):
table.open()
table.codepage = dbf.CodePage('cp1252') # for example
table.close()