您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在python中打开DBF文件时出现问题

在python中打开DBF文件时出现问题

尝试使用我的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()
python 2022/1/1 18:26:39 有191人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶