Visual Fox Pro 和 Python

发布于 2024-10-26 11:44:15 字数 358 浏览 1 评论 0原文

我正在使用 Visual Fox Pro 数据库(.dbf 文件),并且使用 dbf python 模块。这是一个例子:

myDb = VfpTable('table.dbf');

现在我可以通过执行以下操作来排除已删除的项目:

myDb._use_deleted = None; 

我的问题是有没有更简单的方法来做到这一点?也许是一个函数?我讨厌访问“私有”变量。另外,如果不设置此属性,如何确定行是否已被删除?从技术上讲,它们仍然存在于数据库中,所以有一个标志吗?隐藏栏?也许对这个 python 模块或 Visual Fox Pro 有更多了解的人有一些想法。

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 this by doing the following:

myDb._use_deleted = None; 

My question(s) is/are is there an easier way to do this? Maybe a function? I hate accessing "private" variables. Also, without setting this property, how can I determine if a row has been deleted? They are still technically in the database so is there a flag? A hidden column? Maybe someone with more knowledge of this python module or Visual Fox Pro has some ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

能否归途做我良人 2024-11-02 11:44:15

使用上面引用的 dbf 模块 您想要的是:

myDB.use_deleted = False

对于单个记录:

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

物理删除表中记录:

myDB.pack()

披露:我是作者。

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.

任谁 2024-11-02 11:44:15

如果您以前听过这个,请阻止我:“”“我有一个 DBF 读取模块(pydbfrw),我一直想发布“其中一天”。”“”

添加您想要的功能会更容易不想费解 dbf 模块的源代码:

>>> 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)
>>>

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)
>>>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文