如何在python中使用dbf模块忽略已删除的记录?

如何在python中使用dbf模块忽略已删除的记录?,python,foxpro,dbf,Python,Foxpro,Dbf,我正在使用Ethan Furman版本0.96.005(最新版本)在Python2.7中使用的dbf模块,使用的是老式的FoxPro2.x-tables。因为我想忽略已删除的记录,所以在分配tbl=dbf.Table(dbf\u路径)之后,我设置了tbl.use\u deleted=False。我试图在打开表之前和之后将其设置为tbl:…,但 这个和那个似乎都没有任何效果 在记录层面上,我尝试: for rec in tbl: if not rec.has_been_deleted an

我正在使用Ethan Furman版本0.96.005(最新版本)在Python2.7中使用的dbf模块,使用的是老式的FoxPro2.x-tables。因为我想忽略已删除的记录,所以在分配
tbl=dbf.Table(dbf\u路径)
之后,我设置了
tbl.use\u deleted=False
。我试图在打开表之前和之后将其设置为tbl:…,但 这个和那个似乎都没有任何效果

在记录层面上,我尝试:

for rec in tbl:
    if not rec.has_been_deleted and ...
但这给了我:

FieldMissingError: 'has_been_deleted:  no such field in table'

我在做s.th。错了吗?或者该功能不再可用(与5年前一样-请参阅)

使用已删除的
和已删除的
已不存在,并已替换为功能
已删除的

因此,此时您的选择是(假设dbf导入中的
已被删除
):

然后重复这些步骤:

# check active records
for rec in active_records:
    ...

是否已在版本0.97.11中“删除”该U?我遇到了与原来帖子相同的问题,遇到了公认的解决方案。一直在尝试,但得到了名称错误:名称“is_deleted”不是定义的语句。@snowman:如果您只导入了
dbf
(我就是这么做的),那么您需要使用
dbf.is_deleted()
。我意识到我只导入了dbf。我改为from dbf import*,它可以正常工作。
# 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)
# check active records
for rec in active_records:
    ...