2

I'm using dbf-module by Ethan Furman version 0.96.005 (latest one) in Python 2.7 using old-fashioned FoxPro2.x-tables. Since I want to ignore deleted records, I set tbl.use_deleted = False after assigning tbl = dbf.Table(dbf_path). I tried to set this before and after opening the table doing with tbl.open('read-only') as tbl: ..., but neither this nor that seems to have any effect.

On record-level I tried:

for rec in tbl:
    if not rec.has_been_deleted and ...

but that gave me:

FieldMissingError: 'has_been_deleted:  no such field in table'

Am I doing s.th. wrong? Or is that feature not available any more (as it was 5 years ago - see Visual Fox Pro and Python)?

Community
  • 1
  • 1
Orang Mutan
  • 119
  • 1
  • 13

2 Answers2

4

use_deleted and has_been_deleted no longer exist, and have been replaced with the function is_deleted.

So your choices at this point are (assuming a from dbf import is_deleted):

# check each record
for rec in tbl:
    if is_deleted(rec):
        continue

or

# create active/inactive indices

def active(rec):
    if is_deleted(rec):
        return DoNotIndex
    return dbf.recno(rec)

def inactive(rec):
    if is_deleted(rec):
        return recno(rec)
    return DoNotIndex

active_records = tbl.create_index(active)

deleted_records = tbl.create_index(inactive)

and then iterate through those:

# check active records
for rec in active_records:
    ...
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • Has the is_deleted been 'deleted' in version 0.97.11? I was having the same problem as the original post, came across the accepted solution. Have been trying it but get the NameError: name 'is_deleted' is not defined statement. – snowman Feb 21 '19 at 20:12
  • @snowman: If you have only imported `dbf` (which is what I do) then you need to use `dbf.is_deleted()`. – Ethan Furman Feb 22 '19 at 01:43
  • I realized I had only import dbf. I changed to from dbf import * and it works. – snowman Feb 22 '19 at 02:19
0

No existe definida is_deleted use esto:

check each record

for rec in tbl: if if rec._data[0] != "*": continue

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 27 '22 at 08:57