繁体   English   中英

如何使用 python 创建一个新的 .dbf 文件(首选使用 ethanfurman/dbf package 的解决方案)

[英]how can I create a new .dbf file with python (solution with ethanfurman/dbf package will be preferred)

我在ethanfurman/dbf中找不到任何用于将数据写入给定文件路径而不是修改现有文件的公共方法。 我想从元组列表和“field_specs”字符串创建一个 dbf 文件。

此解决方案中,作者提到了 dbf.Table.export() 但我无法从当前版本的 lib 中找到它。

创建表:

import dbf

new_table = dbf.Table('new_file_name.dbf', 'field1 C(10), field2 N(5,2)')

并将记录写入其中(或任何以读/写模式打开的表):

new_table.open(dbf.READ_WRITE)

# using tuples
new_table.append(('a value', 27.31))

# using a dictionary
new_table.append({'field1':'a value', 'field2': 27.31})

暂无
暂无

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

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