Skip to content Skip to sidebar Skip to footer

Visual Fox Pro And Python

I'm working with a visual fox pro database (.dbf file) and I'm using the dbf python module. Heres an example: myDb = VfpTable('table.dbf'); Now I can exclude deleted items with t

Solution 1:

Using the dbf module referenced above what you want is:

myDB.use_deleted = False

and for individual records:

for record in myDB:
    if record.has_been_deleted:
        print"record %d is marked for deletion!" % record.record_number

To physically remove the records from the table:

myDB.pack()

disclosure: I am the author.

Solution 2:

Stop me if you've heard this one before: """I have a DBF reading module (pydbfrw) which I've been meaning to release "one of these days"."""

It was easier to add the functionality that you want than to puzzle through the source code of the dbf module:

>>> import pydbfrw
>>> d = pydbfrw.DBFreader('/devel/dbf/all_files/del.dbf')
>>> list(d)
[['fred', 1], ['harriet', 4]]
>>> d.get_field_names()
['NAME', 'AMT']
>>> d = pydbfrw.DBFreader('/devel/dbf/all_files/del.dbf', include_deleted=True)
>>> list(d)
[[False, 'fred', 1], [True, 'tom', 2], [True, 'dick', 3], [False, 'harriet', 4]]
>>> d.get_field_names()
['deleted__', 'NAME', 'AMT']
>>> for rowdict in d.get_dicts():
... print rowdict
...
{'deleted__': False, 'name': 'fred', 'amt': 1}
{'deleted__': True, 'name': 'tom', 'amt': 2}
{'deleted__': True, 'name': 'dick', 'amt': 3}
{'deleted__': False, 'name': 'harriet', 'amt': 4}
>>> for rowtup in d.get_namedtuples():
... print rowtup
...
Row(deleted__=False, name='fred', amt=1)
Row(deleted__=True, name='tom', amt=2)
Row(deleted__=True, name='dick', amt=3)
Row(deleted__=False, name='harriet', amt=4)
>>>

Post a Comment for "Visual Fox Pro And Python"