gpt4 book ai didi

python - 无法写入 dbf 文件

转载 作者:行者123 更新时间:2023-12-01 02:03:32 26 4
gpt4 key购买 nike

卡住了在 python3 中使用 dbf lib 创建 dbf 文件。

我尝试过这个 -

import dbf
Tbl = dbf.Table( 'sample.dbf', 'ID N(6,0); FCODE C(10)')
Tbl.open('read-write')
Tbl.append()
with Tbl.last_record as rec:
rec.ID = 5
rec.FCODE = 'GA24850000'

并出现下一个错误:

Traceback (most recent call last):
File "c:\Users\operator\Desktop\2.py", line 3, in <module>
Tbl.open('read-write')
File "C:\Users\operator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dbf\__init__.py", line 5778, in open
raise DbfError("mode for open must be 'read-write' or 'read-only', not %r" % mode)
dbf.DbfError: mode for open must be 'read-write' or 'read-only', not 'read-write'

如果我删除“读写” - 接下来:

Traceback (most recent call last):
File "c:\Users\operator\Desktop\2.py", line 4, in <module>
Tbl.append()
File "C:\Users\operator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\dbf\__init__.py", line 5492, in append
raise DbfError('%s not in read/write mode, unable to append records' % meta.filename)
dbf.DbfError: sample.dbf not in read/write mode, unable to append records

我做错了吗?如果我不尝试追加,我只会得到带有正确列的 .dbf,因此 dbf 库可以工作。

最佳答案

我也有同样的错误。在旧版本的 dbf 模块中,我可以通过打开 dbf 文件来编写它们Tbl.open()

但是,使用新版本(dbf.0.97),我必须使用以下命令打开文件Tbl.open(mode=dbf.READ_WRITE)以便能够编写它们。

关于python - 无法写入 dbf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49314270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com