我接到了一个模糊的任务:从各种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 author,dbf
可以读取索引:
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
我只需要读书。我看到有四个类,Idx
,Index
,IndexFile
,和{
Idx
类读取一个表和文件名,这很有前途。在
不过,我不知道如何利用这个对象。我看到它有一些生成器,backward
和{
>>> print(list(index.forward()))
dbf.NotFoundError: 'Record 67305477 is not in table ABC.DBF'
如何将.cdx
索引文件与.dbf
表相关联?在
.idx
和.cdx
不相同,dbf
当前无法读取.cdx
文件。在如果需要对表进行排序,可以创建内存索引:
您还可以创建一个完整的函数:
^{pr2}$然后循环索引而不是表:
相关问题 更多 >
编程相关推荐