python的dbf操作

看网上有dbfread 和 dbfpy 还有dbf几个库,都试着玩一下,暂时发现 dbf库有一直更新,但是还是没法真正删除一行数据。头大。



import datetime
import dbf

# create an in-memory table
table = dbf.Table(r'C:\Users\Administrator\Desktop\20200814\aaa.dbf')
'''
        filename='test',
        field_specs='name C(25); age N(3,0); birth D; qualified L',
        on_disk=False,
        )
'''
#打印dbf文件属性。
print(table.status)

table.open(dbf.READ_WRITE)
'''
# add some records to it
for datum in (
        ('Spanky', 7, dbf.Date.fromymd('20010315'), False),
        ('Spunky', 23, dbf.Date(1989,7,23), True),
        ('Sparky', 99, dbf.Date(), dbf.Unknown),
        ):
#增加数据
    table.append(datum)
#删除数据
    table.
'''
# iterate over the table, and print the records
for record in table:
    #print(record)
    #print('--------')
    #print(record[0:15])
    #print([record.name, record.age, record.birth])
    print(record[0],"table is delete?:",is_deleted(record))
    print('--------')

    # delete every third record
    i = 0
    for record in table:
        #self.assertEqual(dbf.recno(record), i)
        dbf.recno(record)
        if i % 3 == 0:
            dbf.delete(record)
        i += 1
    i = 0
dbf.delete(table[1])
#dbf.pql_delete(table[1])
#dbf.remove
#dbf.pack_str(
print(table)
'''
# make a copy of the test table (structure, not data)
custom = table.new(
        filename='test_on_disk',
        default_data_types=dict(C=dbf.Char, D=dbf.Date, L=dbf.Logical),
        )

# automatically opened and closed
with custom:
    # copy records from test to custom
    for record in table:
        custom.append(record)
    # modify each record in custom (could have done this in prior step)
    for record in custom:
        dbf.write(record, name=record.name.upper())
        # and print the modified record
        print(record)
        print('--------')
        print(record[0:3])
        print([record.name, record.age, record.birth])
        print('--------')
'''
table.close()

你可能感兴趣的:(python)