双向固定宽度<-->python dict转换器。
FixedWidth的Python项目详细描述
python字典和固定宽度文件之间的简单双向转换。 FixedWidth类已在生产中使用,未对 好几年了。
此模块也被证明对“调试”固定宽度规范很有用-- 无效配置报告的错误可能不明显 正在读取规范文档。
需要“config”指令。完整的例子见单元测试。
小示例
SAMPLE_CONFIG = {
'first_name': {
'required': True,
'type': 'string',
'start_pos': 1,
'end_pos': 10,
'alignment': 'left',
'padding': ' '
},
'last_name': {
'required': True,
'type': 'string',
'start_pos': 11,
'end_pos': 30,
'alignment': 'left',
'padding': ' '
},
'date': {
'required': True,
'type': 'date',
'start_pos': 31,
'end_pos': 38,
'alignment': 'left',
'format': '%Y%m%d',
'padding': ' '
},
'decimal': {
'required': True,
'type': 'decimal',
'precision': 2,
'rounding': decimal.ROUND_UP,
'start_pos': 38,
'end_pos': 42,
'alignment': 'left',
'padding': ' '
},
}
注意:
字段必须有开始位置和结束位置或长度。如果同时提供了结束位置和长度,则它们不能冲突。
如果需要,字段可能没有默认值。
支持的类型有string、integer和decimal。
需要对齐和填充。
许可证:BSD