Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Two-way fixed-width <--> Python dict converter.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for FixedWidth, version 1.3
Filename, size File type Python version Upload date Hashes
Filename, size FixedWidth-1.3-py3-none-any.whl (5.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size FixedWidth-1.3.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page