在 python dbf 中使用 ^ 等特殊字符定义字段名称
Defining Field names with special characters such as ^ in python dbf
我想用可能包含 ^ 字符的字段名称定义一个 DBF table。
我正在使用以下 table 定义:
tbl_SubDBF = dbf.Table("..//output//Ttest.dbf", \
'B^AWG C(50); C^PTYPE C(200)')
我收到如下 fieldspecerror:
field names must start with a letter, and can only contain letters, digits, and _
是否有解决方法(转义字符)允许我在创建 dbf table 时定义上面提到的 headers?
我正在使用 python 3.7
原答案
据我所知,dbf 字段规范不允许在字段名称中使用非字母数字字符。目前唯一可能的解决方法是继承 Table
并将失败的方法替换为允许奇怪字符的方法。
更新答案
查看有问题的方法 (add_fields
),替换它是一项艰巨的任务。因此,从 dbf 0.98.0
开始,可以在字段名称中使用 wants/needs 任何奇怪的字符,但 dbf 会生成警告:
<module>:<line_no>: FieldNameWarning: "p^type invalid: field names should start with a letter, and only contain letters, digits, and _
some_dbf.add_fields('p^type C(25)')
要取消该警告,可以添加:
import warnings
warnings.filterwarnings('ignore', '', dbf.FieldNameWarning)
我想用可能包含 ^ 字符的字段名称定义一个 DBF table。 我正在使用以下 table 定义:
tbl_SubDBF = dbf.Table("..//output//Ttest.dbf", \
'B^AWG C(50); C^PTYPE C(200)')
我收到如下 fieldspecerror:
field names must start with a letter, and can only contain letters, digits, and _
是否有解决方法(转义字符)允许我在创建 dbf table 时定义上面提到的 headers?
我正在使用 python 3.7
原答案
据我所知,dbf 字段规范不允许在字段名称中使用非字母数字字符。目前唯一可能的解决方法是继承 Table
并将失败的方法替换为允许奇怪字符的方法。
更新答案
查看有问题的方法 (add_fields
),替换它是一项艰巨的任务。因此,从 dbf 0.98.0
开始,可以在字段名称中使用 wants/needs 任何奇怪的字符,但 dbf 会生成警告:
<module>:<line_no>: FieldNameWarning: "p^type invalid: field names should start with a letter, and only contain letters, digits, and _
some_dbf.add_fields('p^type C(25)')
要取消该警告,可以添加:
import warnings
warnings.filterwarnings('ignore', '', dbf.FieldNameWarning)