从 Python 读取 FoxPro DBF 文件的最简单方法是什么?
我的 Ubuntu 系统上有一堆 FoxPro (VFP9) DBF 文件,是否有库可以在 Python 中打开这些文件? 我只需要阅读它们,并且最好也能访问备注字段。
更新:谢谢@cnu,我使用了 Yusdi Santoso 的 dbf.py
它工作得很好。 一个问题是:备忘录文件扩展名必须是小写,即 .fpt
,而不是 .FPT
,后者是 Windows 中文件名的来源。
I've got a bunch of FoxPro (VFP9) DBF files on my Ubuntu system, is there a library to open these in Python? I only need to read them, and would preferably have access to the memo fields too.
Update: Thanks @cnu, I used Yusdi Santoso's dbf.py
and it works nicely. One gotcha: The memo file name extension must be lower case, i.e. .fpt
, not .FPT
which was how the filename came over from Windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我更喜欢 dbfpy。 它支持
.DBF
文件的读取和写入,并且可以处理大多数格式的变化。 这是我发现的唯一可以读取和写入我使用过的一些旧系统的遗留 DBF 文件的实现。I prefer dbfpy. It supports both reading and writing of
.DBF
files and can cope with most variations of the format. It's the only implementation I have found that could both read and write the legacy DBF files of some older systems I have worked with.如果您仍在检查这一点,我在 https://github.com/ 上有一个 GPL FoxPro 到 PostgreSQL 转换器kstrauser/pgdbf 。 我们使用它定期将表复制到 PostgreSQL 中以实现快速报告。
If you're still checking this, I have a GPL FoxPro-to-PostgreSQL converter at https://github.com/kstrauser/pgdbf . We use it to routinely copy our tables into PostgreSQL for fast reporting.
您可以尝试这个活动状态秘诀。
还有一个 DBFReader 模块,您可以使用它可以尝试。
支持备注字段。
You can try this recipe on Active State.
There is also a DBFReader module which you can try.
For support for memo fields.
请查看 http://groups.google.com/group/python-dbase
目前 支持 dBase III 和 Visual Foxpro 6.0 db 文件...不确定 VFP 9 中的文件布局是否发生变化...
Check out http://groups.google.com/group/python-dbase
It currently supports dBase III and Visual Foxpro 6.0 db files... not sure if the file layout change in VFP 9 or not...
现在是 2016 年,我不得不摆弄 dbf 包才能让它工作。 这是一个 python3 版本,用于将 dbf 文件导出到 csv
我一开始遇到了一些 unicode 错误,但通过关闭备忘录解决了这个问题。
It's 2016 now and I had to fiddle with the dbf package to get it to work. Here is a python3 version to just export a dbf file to a csv
I had some unicode error at first, but got around that by turning off memos.
我能够使用 PyPI http: //pypi.python.org/pypi/dbf 。 我是 python 新手,对 DBF 文件一无所知,但是从我女朋友的公司(使用名为 AIMsi 的音乐商店 POS 应用程序创建)读取 DBF 文件很容易。
安装 dbf 包后(我使用了 aptitude 并安装了 dbf 版本 0.88),以下 python 代码起作用了:
这就是我现在所知道的,但希望这对于发现这个问题的其他人来说是一个有用的开始!
I was able to read a DBF file (with associated BAK, CDX, FBT, TBK files**) using the dbf package from PyPI http://pypi.python.org/pypi/dbf . I am new to python and know nothing about DBF files, but it worked easily to read a DBF file from my girlfriend's business (created with a music store POS application called AIMsi).
After installing the dbf package (I used aptitude and installed dbf version 0.88 I think), the following python code worked:
That's all I know for now, but hopefully it's a useful start for someone else who finds this question!