Search code examples
pythondbf

Under Python, use DBF package0.96.8. can I insert a blank record in any position within a DBF file?


I encountered this problems for a few days, can not find a solution so far.


Solution

  • Not easily.


    To answer the question asked:

    The only way to physically insert a record (blank or otherwise) at a particular location would be to create a new dbf, copy all the records that go before the new one over, then create the new one, then copy all the following records, and finally delete the original file and rename the new one to take its place.


    To answer the question I guess you were answering:

    You can create temporary, in-memory indexes and use those to iterate over your records:

    table = dbf.Tableh('sometablehere.dbf')
    member_order = table.create_index(lambda record: record.member_no)
    for record in member_order:
        print record  # this happens in member_no order