从Python中读取FoxPro DBF文件最简单的方法是什么?

2024-09-28 19:07:59 发布

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

我的Ubuntu系统上有很多FoxPro(VFP9)DBF文件,有没有用Python打开的库?我只需要阅读它们,最好也可以访问备注字段。

更新:谢谢@cnu,我使用了Yusdi Santoso的^{},它工作得很好。一个问题是:memo文件扩展名必须是小写,即.fpt,而不是.FPT,这是文件名从Windows传过来的方式。


Tags: 文件文件名ubuntuwindows系统小写memodbf
3条回答

你可以试试这个recipe on Active State

还有一个DBFReader module你可以试试。

支持memo fields

我更喜欢dbfpy。它支持读取和写入.DBF文件,并且可以处理格式的大多数变体。这是我发现的唯一一个既可以读写我使用过的一些旧系统的遗留DBF文件的实现。

我能够使用PyPIhttp://pypi.python.org/pypi/dbf中的DBF包读取DBF文件(以及相关的BAK、CDX、FBT、TBK文件**)。我是python新手,对DBF文件一无所知,但从我女朋友的公司(使用名为AIMsi的音乐商店POS应用程序创建)读取DBF文件很容易。

在安装dbf包(我使用aptitude并安装了dbf版本0.88)之后,以下python代码工作了:

from dbf import *
test = Table("testfile.dbf")
for record in test:
    print record
    x = raw_input("")  # to pause between showing records

这是我现在所知道的,但希望这是一个有用的开始,为其他人谁发现这个问题!

April 21, 2012 SJK Edit: Per Ethan Furman's comment, I should point out that I actually don't know which of the data files were necessary, besides the DBF file. The first time I ran the script, with only the DBF available, it complained of a missing support file. So, I just copied over the BAK, CDX, FPT (not FBT as I said before edit), TBK files and then it worked.

相关问题 更多 >