简体   繁体   English

如何在 Python 的 DBF 库中编辑单个条目

[英]How to edit individual entries in the DBF Library for Python

Wondering how I can edit individual values using Ethan Furman's dbf library.想知道如何使用 Ethan Furman 的 dbf 库编辑单个值。 I can edit the fields using我可以使用编辑字段

with dbf.Table(insertPreviouslyAssignedValueHere) as table:
    for record in dbf.Process(table):
        record[field] = desiredValue

but this edits an entire column to be the same value.但这会将整个列编辑为相同的值。 I need a way to edit values anywhere in the file individually as well as add new rows to edit.我需要一种方法来单独编辑文件中任何位置的值以及添加新行进行编辑。 I've tried reading over some old documentation here but I can't find a function for editing individual cells.我尝试在这里阅读一些旧文档,但找不到用于编辑单个单元格的 function。 I can also peek at an individual value though不过,我也可以窥视个人价值

table[column][row]

But still, no editing feature in this fashion.但是,仍然没有这种方式的编辑功能。

A record is also a context manager, so:记录也是上下文管理器,因此:

with table[column][row] as rec:
    rec.some_field = 77

will work.将工作。 The advantage of doing it this way is that if you are updating multiple fields, and one of the assignments raises an exception, the record is not updated and so not in an inconsistent state.这样做的好处是,如果您要更新多个字段,并且其中一个分配引发异常,则不会更新记录,因此不会出现不一致的 state。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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