简体   繁体   中英

Open a DBF file from a BytesIo

I try to remove fields from a DBF that I get from internet.

It is zipped and in order to avoid to write any data on the disk before applying the modifications I have to do on it, I extract it into a BytesIo object.

Then, first : Does the dbf library handles memory files like BytesIo? Second : Is my unwanted fields removal method efficient?

Here is what I ended up with:

def removeFields(name, raw):
    import dbf

    data = io.BytesIO(raw)
    print "Editing "+name
    table = dbf.Table(data, on_disk=False)
    table.open()
    table.delete_fields(rmv_dict[name])
    table.close()
    return (data.getvalue())

Regrettably, the dbf library doesn't handle any memory files (confirmed by her author). Some like dbfread handle them, but don't provide any method to delete fields simply in their docs.

Fortunately, I found a recipe for reading/writing dbf files with variables that are easy to handle : http://code.activestate.com/recipes/362715-dbf-reader-and-writer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM