[英]How to ignore deleted records using dbf-module in python?
I'm using dbf-module by Ethan Furman version 0.96.005 (latest one) in Python 2.7 using old-fashioned FoxPro2.x-tables. 我正在使用老式FoxPro2.x-tables在Python 2.7中使用Ethan Furman版本0.96.005(最新版本)的dbf-module。 Since I want to ignore deleted records, I set tbl.use_deleted = False
after assigning tbl = dbf.Table(dbf_path)
. 由于我想忽略已删除的记录, tbl.use_deleted = False
在分配tbl = dbf.Table(dbf_path)
之后设置tbl.use_deleted = False
。 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. 我试图在with tbl.open('read-only') as tbl: ...
将表打开之前和之后将其设置with tbl.open('read-only') as tbl: ...
,但是这似乎都没有任何效果。
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 )? 还是该功能不再可用(就像5年前一样-请参阅Visual Fox Pro和Python )?
use_deleted
and has_been_deleted
no longer exist, and have been replaced with the function is_deleted
. use_deleted
和has_been_deleted
不再存在,并已由is_deleted
函数is_deleted
。
So your choices at this point are (assuming a from dbf import is_deleted
): 因此,此时您的选择是(假设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:
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.