Alright, I'm using an ancient database format here, dbf files. Don't ask why, just know a certain software decided to extend foxpro support because microsoft decided to extend foxpro support. Now, I'm getting the following error on a specific file. I have successfully loaded another file and I'm curious if there is something wrong with this database. I'm sure you probably need to look at the database to determine that, but its way to huge to post so I'll take what I can get.
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'
And heres my simple code that is returning this error:
def getUsedGuns(self):
itemdb = dbf.Dbf('item.dbf', readOnly=True, ignoreErrors=True)
Like I said, I can load other files with out a problem but maybe there is a work around for this specific error?
EDIT: I'd also like to point out that the file can be opened and viewed and modified in DBF View Plus.
EDIT: Solution Found. I actually ended up using the python dBase module. I think my main problem was not having the memo files around(whatever they are, it has a .fpt file extension). Heres what I am using at the moment:
from dbf.tables import VfpTable
itemdb = VfpTable('item.db')
for rec in itemdb:
print rec['MY_COLUM_NAME']
I'd also like to point out that anyone currently still using FoxPro should be burned.
*.dbf
) contain fixed-width records, memo fields don't fit nicely. Therefore, they get their own file with its own format. – Adam Paynter