好吧,我在这里使用一种古老的数据库格式,dbf 文件。不要问为什么,只知道某个软件决定扩展foxpro支持是因为微软决定扩展foxpro支持。现在,我在特定文件上收到以下错误。我已经成功加载了另一个文件,我很好奇这个数据库是否有问题。我相信您可能需要查看数据库来确定这一点,但它的发布方式非常庞大,所以我会尽我所能。
Traceback (most recent call last):
File "billsapi.py", line 250, in <module>
x.getUsedGuns()
File "billsapi.py", line 72, in getUsedGuns
itemdb = dbf.Dbf('item.dbf', readOnly=True, ignoreErrors=True)
File "C:\Python27\lib\site-packages\dbfpy\dbf.py", line 135, in __init__
self.header = self.HeaderClass.fromStream(self.stream)
File "C:\Python27\lib\site-packages\dbfpy\header.py", line 127, in fromStream
_fld = fields.lookupFor(_data[11]).fromString(_data, _pos)
File "C:\Python27\lib\site-packages\dbfpy\fields.py", line 455, in lookupFor
return _fieldsRegistry[typeCode]
KeyError: '0'
这是我返回此错误的简单代码:
def getUsedGuns(self):
itemdb = dbf.Dbf('item.dbf', readOnly=True, ignoreErrors=True)
就像我说的那样,我可以毫无问题地加载其他文件,但也许可以解决这个特定错误?
编辑:我还想指出,可以在 DBF View Plus 中打开、查看和修改该文件。
编辑:找到解决方案。我实际上最终使用了 python dBase 模块。我认为我的主要问题是没有备忘录文件(无论它们是什么,它都有一个 .fpt 文件扩展名)。这是我目前使用的:
from dbf.tables import VfpTable
itemdb = VfpTable('item.db')
for rec in itemdb:
print rec['MY_COLUM_NAME']
我还想指出,目前仍在使用 FoxPro 的任何人都应该被烧毁。