我想使用DBF模块根据dist列中的值来拆分vfp。因此,我提取了所有必要的指数,用于出口。不幸的是,原始表不允许索引列表。
input_file = 'refrence.dbf'
table = dbf.Table(input_file)
l = []
for ind, record in enumerate(table.open(mode=dbf.READ_WRITE)):
with record as r:
if r.dist >= start and r.dist <= end:
l.append(ind)是否有更简单的方法来获得n个单独的dbf文件,其中只包含满足条件r.dist >= start and r.dist <= end的行?
发布于 2018-04-11 15:35:47
我将尝试如下(未经测试):
def copy_range(source, destination, field_name, start, end):
src = dbf.Table(source).open()
dst = src.new(destination).open(dbf.READ_WRITE) # copy structure
for record in src:
if start <= record[field_name] <= end:
dst.append(record)
src.close()
dst.close()然后把它叫做:
copy_range('refrence.dbf', 'result.dbf', 'dist', 100, 200)发布于 2018-04-11 17:13:30
选择记录可以通过以下方式完成:
target_records = [rec for rec in table if start <= rec.dist <= end]一旦有了这些记录,就很容易将它们复制到一个新的dbf中:
new_table = old_table.new('some_file.dbf')
with new_table:
for record in target_records:
new_table.append(record)发布于 2018-04-13 18:50:09
您可以像这样访问已过滤的表
table[l]["dist"]或
table[l][fieldName]或
table[l][0]您应该使用这些过滤过的数据生成dbf文件。
https://stackoverflow.com/questions/49778278
复制相似问题