Skip to content
This repository was archived by the owner on May 6, 2019. It is now read-only.
/ fixedwidth Public archive
forked from ShawnMilo/fixedwidth

Python fixed-width to/from dict converter.

Notifications You must be signed in to change notification settings

oscaro/fixedwidth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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': ' '
    },

}

Notes:

  1. 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.
  2. A field may not have a default value if it is required.
  3. Supported types are string, integer, and decimal.
  4. Alignment and padding are required.

About

Python fixed-width to/from dict converter.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%