-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: could not convert string to float #20
Comments
Thanks for reporting this. This is the first time I see a binary N field. I would add your changes but I'm worried that it would cause other files to fail. For example, the value Do you know what software was used to create the file? |
My solution was to simply strip out all null from dbfread import FieldParser
class MyFieldParser(FieldParser):
def parseN(self, field, data):
data = data.strip().strip(b'*\x00') # Had to strip out the other characters first before \x00, as per super function specs.
return super(MyFieldParser, self).parseN(field, data)
def parseD(self, field, data):
data = data.strip(b'\x00')
return super(MyFieldParser, self).parseD(field, data)
# Usage
db = DBF("mydbf.dbf", parserclass=MyFieldParser) I'm converting some old-school point-of-sale databases over to a newer database. I'm not sure if the data is simply corrupt in the DBF (although Excel doesn't seem to mind opening them without warning). The newer sets of DBFs in my collection doesn't seem to have this issue so I'm thinking it could just be improper file handling from older software. Hope this helps someone. Edit: Added |
Through reading other issues I have found a way to fix the problem, but I'm not sure of the best way to implement it.
This works in my instance, but there may be a better way to implement, I'm not sure of the best way to make the comparison to find if the data object is a byte literal, I had also made the comparison as such,
data == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Hope this helps
The text was updated successfully, but these errors were encountered: