PythonDBF:如何将.cdx索引与.DBF选项卡相关联

2024-05-14 18:36:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我接到了一个模糊的任务:从各种visualfoxpro表中自动提取数据。在

有几个.DBF.CDX文件对。有了Pythondbf包,我似乎可以使用它们。我有两个文件,一个ABC.DBF和一个ABC.CDX。我可以用加载表文件

>>> import dbf
>>> table = dbf.Table('ABC.DBF')
>>> print(table[3])
  0 - table_key : '\x00\x00\x04'
  1 - field_1   : -1
  2 - field_2   : 0
  3 - field_3   : 34
  4 - field_ 4  : 2
  ...

>>>

我的理解是.cdx文件是索引。我怀疑它对应于table_key字段。According to the authordbf可以读取索引:

I can read IDX files, but not update them. My day job changed and dbf files are not a large part of the new one. – Ethan Furman May 26 '16 at 21:05

我只需要读书。我看到有四个类,IdxIndexIndexFile,和{}。这些似乎是很好的候选人。在

Idx类读取一个表和文件名,这很有前途。在

^{pr2}$

不过,我不知道如何利用这个对象。我看到它有一些生成器,backward和{},但是当我尝试使用它们时,我得到了一个错误

>>> print(list(index.forward()))
dbf.NotFoundError: 'Record 67305477 is not in table ABC.DBF'

如何将.cdx索引文件与.dbf表相关联?在


Tags: 文件thekeyfieldtablenotfilesabc

热门问题