gpt4 book ai didi

python - 在 python dbf 中使用 ^ 等特殊字符定义字段名称

转载 作者:太空宇宙 更新时间:2023-11-04 04:18:30 24 4
gpt4 key购买 nike

我想定义一个 DBF 表,其中的字段名称可能包含 ^ 字符。我正在使用下表定义:

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 表时定义上述标题?

我正在使用 python 3.7

最佳答案

原始答案

据我所知,dbf 字段规范不允许在字段名称中使用非字母数字字符。目前唯一可能的解决方法是继承 Table 并将失败的方法替换为允许奇怪字符的方法。


更新的答案

查看有问题的方法 (add_fields),替换它是一项重大努力。因此,从 dbf 0.98.0 开始,人们可以在字段名称中使用任何想要/需要的奇怪字符,但 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)

关于python - 在 python dbf 中使用 ^ 等特殊字符定义字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54985996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com