Git Product home page Git Product logo

Comments (2)

pbrn46 avatar pbrn46 commented on July 28, 2024 2

My solution was to simply strip out all null \x00 characters before processing numbers and dates. I've added this code in my own customer parser that overrides parseN and parseD:

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 import line to code

from dbfread.

olemb avatar olemb commented on July 28, 2024

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 b' 3.14' could be parsed either as text (3.14) or as binary (858665268), but without any context there's no way to tell which one to choose. (parseN() will always get data as a byte string so you can't tell by its type.)

Do you know what software was used to create the file?

from dbfread.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.