首页 > 解决方案 > 处理 foxpro dbf 文件中已删除记录的问题

问题描述

我总是收到以下消息:

is_deleted() 未定义

这是我的python程序。我究竟做错了什么?

import dbf

tableDirsync = dbf.Table("o:/python/dirsync.dbf")
tableDirsync.open()

for dirsync in tableDirsync:
    if is_deleted(dirsync):
        continue
    else:  
        print(dirsync.diri1, dirsync.diro1)

tableDirsync.close()
mainloop()

标签: pythonfoxprodbf

解决方案


来自 phyton dbf 包的文档(请参阅在此处输入链接描述:)

Check if a record has been marked as deleted:
        record = table[1] # for example
        if record.has_been_deleted:
            print "table.pack() will physically remove this record! (and all other deleted records)"

所以在你的情况下:

import dbf

tableDirsync = dbf.Table("o:/python/dirsync.dbf")
tableDirsync.open()

for dirsync in tableDirsync:
    if dirsync.has_been_deleted:
        continue
    else:  
        print(dirsync.diri1, dirsync.diro1)

tableDirsync.close()
mainloop()

推荐阅读