我试过两个模块,用于读取dbf文件(dbf和dbfpy),但我必须通过记录读取数据库记录来查找内容。这对于大型数据库来说确实很慢。是否有任何模块可以处理查询表或使用CDX索引?用python高效读取foxpro DBF
2
A
回答
2
我不相信dbfpy
支持索引文件,而且我知道dbf
没有。
然而,在dbf
您可以创建一个临时索引,然后查询是:
big_table = dbf.Table('/path/to/some/big_table')
def criteria(record):
"index the table using these fields"
return record.income, record.age
index = big_table.create_index(key=criteria)
index
现在可以itereated过,或搜索返回所有匹配的记录:
for record in index.search(match=(50000, 30)):
print record
样本表:
table = dbf.Table('tempu', 'name C(25); age N(3,0); income N(7,0);')
table.open()
for name, age, income in (
('Daniel', 33, 55000),
('Mike', 59, 125000),
('Sally', 33, 77000),
('Cathy', 41, 50000),
('Bob', 19, 22000),
('Lisa', 19, 25000),
('Nancy', 27, 50000),
('Oscar', 41, 50000),
('Peter', 41, 62000),
('Tanya', 33, 125000),
):
table.append((name, age, income))
index = table.create_index(lambda rec: (rec.age, rec.income))
还有碰到部门首长搜索范围的开头和结尾:
# all the incomes of those who are 33
for rec in index.search(match=(33,), partial=True):
print repr(rec)
print
# all the incomes of those between the ages of 40 - 59, inclusive
start = index.index_search(match=(40,), nearest=True)
end = index.index_search(match=(60,), nearest=True)
for rec in index[start:end]:
print repr(rec)
它打印:
Daniel 33 55000
Sally 33 77000
Tanya 33 125000
Cathy 41 50000
Oscar 41 50000
Peter 41 62000
Mike 59 125000
+0
这花了大约两倍的时间。我猜,因为它必须创建索引,然后通过它循环。 – user3727436
+0
@ user3727436:你能编辑你的答案并发布你试过的代码吗?创建索引会循环遍历整个表,但在此之后(使用适当的成语)查找应该使用二进制algorythm。 –
相关问题
- 1. Php读取Foxpro DBF文件
- 2. 从PHP/Linux读取Foxpro文件(.DBF)
- 3. foxpro dbf查询
- 4. C#visual foxpro dbf indices
- 5. 读取记录dbf foxpro 2.6已在excel上删除
- 6. 无法读取Visual FoxPro DBF文件中的编码文本
- 7. Foxpro FPD DBF开放问题
- 8. 用pyodbc读取DBF文件
- 9. Visual FoxPro DBF更新使用PHP
- 10. FoxPro:如何从独占锁定的DBF表文件读取数据?
- 11. 用Python在Linux上高效地读取csv文件在Python中
- 12. 在foxpro dbf中创建多列索引?
- 13. c#如何正确写入.dbf(foxpro)
- 14. 如何插入到DBF文件(FoxPro的)
- 15. 在dbf-visual foxpro中搜索数据9
- 16. 为FoxPro DBF(自由表)C#代码
- 17. Python dbfpy和FoxPro
- 18. 使用OLEDB读取FoxPro中的特殊字符
- 19. 使用python中的dbf库读取更改
- 20. 用Java读取FoxPro 2.6数据
- 21. 使用Python 2.7高效读取800 GB XML文件
- 22. 如何高效地用python读取cap文件?
- 23. Python - 读取文件夹中的所有文件(.shp,.dbf,.mxd等)
- 24. 使用Advantage Local Sever和FoxPro同时更新DBF文件
- 25. python dbf reader:NotImplementedError
- 26. python dbf到mysql
- 27. Asp.net读取文件.dbf错误conn.Open()
- 28. 如何直接读取dbf/dbt文件?
- 29. 读DBF文件/硒
- 30. 使用ODBC从Java读取Visual Foxpro数据
根据您的平台,我想你可以尝试操作系统级别的外部接口,如ODBC/JDBC。 –