Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't write dbf file

Tags:

python

dbf

stuck with create dbf file in python3 with dbf lib.

im tried this -

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' 

and have next error:

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'

if im remove 'read-write' - next:

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

thats im doing wrong? if im not try append, im just get .dbf with right columns, so dbf library works.

like image 863
Никита Седавных Avatar asked Sep 23 '26 00:09

Никита Седавных


2 Answers

I had the same error. In the older versions of the dbf module, I was able to write dbf files by opening them just with Tbl.open()

However, with the new version (dbf.0.97), I have to open the files with Tbl.open(mode=dbf.READ_WRITE) in order to be able to write them.

like image 77
basser Avatar answered Sep 24 '26 14:09

basser


here's an append example:

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)
like image 23
AdiBR Avatar answered Sep 24 '26 13:09

AdiBR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!