python - 在 python dbf 中使用特殊字符定义字段名称,例如 ^
问题描述
我想定义一个字段名称可能包含 ^ 字符的 DBF 表。我正在使用下表定义:
tbl_SubDBF = dbf.Table("..//output//Ttest.dbf", \
'B^AWG C(50); C^PTYPE C(200)')
我收到如下字段规范错误:
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)
推荐阅读
- scala - SBT、Scala、Spark、IntelliJ
- r - 如何识别数据集中的重复子序列
- javascript - jit 编译器在 JAVASCRIPT 中是如何工作的
- android - 设备充电时 CPU 是否保持唤醒状态?
- python - 如何在 Sprite 的底部添加额外的图像或矩形?
- python-3.x - 使用 Python 在 Google 地图中测量区域
- java - 获取 JWT 后,带有 Spring Boot 后端的 Angular 在现有路由上返回 404
- reactjs - AG-Grid 仅更改 rowData 时使用的回调是什么
- python - 不计算文件中的正确字符
- blueprism - 如何在 BluePrism 的集合中找到行索引?