Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ShawnMilo/fixedwidth
Python fixed-width to/from dict converter.
https://github.com/ShawnMilo/fixedwidth
Last synced: 3 months ago
JSON representation
Python fixed-width to/from dict converter.
- Host: GitHub
- URL: https://github.com/ShawnMilo/fixedwidth
- Owner: ShawnMilo
- License: bsd-2-clause
- Created: 2012-12-08T21:20:49.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-05-03T11:09:58.000Z (over 5 years ago)
- Last Synced: 2024-07-22T19:36:35.660Z (3 months ago)
- Language: Python
- Size: 42 KB
- Stars: 46
- Watchers: 8
- Forks: 39
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- starred-awesome - fixedwidth - Python fixed-width to/from dict converter. (Python)
README
Easy two-way conversion between Python dictionaries and fixed-width files.
The FixedWidth class has been used in production without modification for
several years.This module has also proven useful for "debugging" a fixed-width spec --
an invalid configuration reports an error that may not be obvious from
reading the spec document.Requires a 'config' dictonary. See unit tests for full example.
Small example
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': ' '
},}
Notes:
* A field must have a start_pos and either an end_pos or a length. If both an end_pos and a length are provided, they must not conflict.
* A field may not have a default value if it is required.
* Supported types are string, integer, and decimal.
* Alignment and padding are required.
License: BSD