在python3中使用dbf创建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库可以工作。
发布于 2018-03-17 18:04:29
我也犯了同样的错误。在dbf模块的旧版本中,我能够通过仅用Tbl.open()打开dbf文件来编写dbf文件。
但是,对于新版本(dbf.0.97),为了能够编写这些文件,我必须用Tbl.open(mode=dbf.READ_WRITE)打开它们。
发布于 2019-04-15 11:39:26
下面是一个附加的示例:
table = dbf.Table('sample.dbf', 'cod N(1,0); name C(30)')
table.open(mode=dbf.READ_WRITE)
row_tuple = (1, 'Name')
table.append(row_tuple)https://stackoverflow.com/questions/49314270
复制相似问题