How to delete record from dbf file using python dbf module?

191
February 16, 2018, at 11:23 PM

I'm trying to write/delete records in a visual foxpro 6 dbf file, using python 2.7 and the dbf package:

import dbf
tbl = dbf.Table('test.dbf')
tbl.open()
rec = tbl[0]
print(rec.__class__)
rec.delete_record()

Result:

<class 'dbf.ver_2.Record'>
Traceback (most recent call last):
  File "C:/Python/Projects/test/test.py", line 11, in <module>
    rec.delete_record()
  File "C:\Python\Projects\test\venv\lib\site-packages\dbf\ver_2.py", line 2503, in __getattr__
    raise FieldMissingError(name)
dbf.ver_2.FieldMissingError: 'delete_record:  no such field in table'

Here is the documentation for that package: http://pythonhosted.org/dbf/

The record object really does not have this method, but it is documented. The table is opened in read-write mode. (But it is also true that the Table() constructor should return an opened table, but it returns a closed table instead.)

What am I doing wrong?

The biggest problem is that there are no other options. The only other package I know of is "dbfpy" but that does not handle vfoxpro 6 tables, and it does not handle different character encodings.

Answer 1

That documentation is out of date. (My apologies.)

What you want is:

dbf.delete(rec)
tbl.pack()
READ ALSO
&#39;DataFrame&#39; object has no attribute &#39;data&#39; but I have added it in my dataset

'DataFrame' object has no attribute 'data' but I have added it in my dataset

I was following this tutorial on using deep belief networks https://wwwpyimagesearch

120
Accuracy tuning for RandomForestRegressor : Scikit

Accuracy tuning for RandomForestRegressor : Scikit

I am trying to lower the RMSE score for my model: But no matter what parameter I change, the RMSE value always remains between 039 to 0

178
Restricted Terminal Linux [on hold]

Restricted Terminal Linux [on hold]

This sounds like a stupid question but I have tried to research Linux restricted terminals and have not found what I am looking forI am not overly familiar with Linux, restricted or otherwise, and I want to run a python code that already exists within...

153
Tensorflow bias and weight variable

Tensorflow bias and weight variable

I have created a deep convolutional neural network for pixel-wise classificationMy images for training are of size 32x32x7, therfore the number 7168 is used a lot

190