Skip to main content

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

Project description

Read Positional Files from a config Files:

Easy two-way conversion between Python dictionaries and fixed-width files.

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.

    "Tipo_registro": {
        "required": True,
        "type": "integer",
        "start_pos": 1,
        "end_pos": 1
    },

    "estabelecimento_matriz": {
        "required": True,
        "type": "integer",
        "start_pos": 2,
        "end_pos": 11,
        "length": 10,
    },

    "data_processamento": {
        "required": True,
        "type": "integer",
        "start_pos": 12,
        "end_pos": 19,
        "length": 8,

    },

    "Periodo_inicial": {
        "type": "integer",
        "start_pos": 20,
        "end_pos": 27,
        "length": 8,
        "required": True
    },

    "Periodo_final": {
        "type": "integer",
        "start_pos": 28,
        "end_pos": 35,
        "length": 8,
        "required": True
    },

    "sequencia": {
        "type": "integer",
        "start_pos": 36,
        "end_pos": 42,
        "length": 7,
        "required": True
    },

    "empresa_adquirente": {
        "required": True,
        "type": "string",
        "start_pos": 43,
        "end_pos": 47,
        "length": 5
        },

    "opcao_extrato": {
        "required": True,
        "type": "integer",
        "start_pos": 48,
        "end_pos": 49,
        "length": 2
        },

    "van": {
        "required": True,
        "type": "string",
        "start_pos": 50,
        "end_pos": 50,
        "length": 1
        },

    "caixa_postal": {
        "required": False,
        "type": "string",
        "start_pos": 51,
        "end_pos": 70,
        "length": 20
        },

    "versão_layout": {
        "required": False,
        "type": "integer",
        "start_pos": 71,
        "end_pos": 73,
        "length": 3
        }
}


def test_fw_to_dict():
    """
    Pass in a line and receive dictionary.
    """

    fw_config = deepcopy(layouts.TIPO2CONFIG)

    fw_obj = FixedWidth(fw_config)
    fw_obj.line = ("210274391334190626532930******311000020190626+00000000352340103   R64061                    79398900000000000001600000000000000000000000000000000000000129000454                      00000019177510012466900000010001001 05                              ")

    values = fw_obj.data

    valid = fw_obj.is_valid



    print(values)
    print(valid)


test_fw_to_dict()

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.

License: BSD

Project details


Release history Release notifications | RSS feed

This version

1.2

Download files

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

Source Distribution

readEdi-1.2.tar.gz (2.3 kB view details)

Uploaded Source

File details

Details for the file readEdi-1.2.tar.gz.

File metadata

  • Download URL: readEdi-1.2.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16

File hashes

Hashes for readEdi-1.2.tar.gz
Algorithm Hash digest
SHA256 b2669f357be49e161e2ffa9ea9d7428888b7b049d5c2fb7f8947d3a95e39c5ee
MD5 802b564dcb899cf913ab6a57d2b24023
BLAKE2b-256 ef9a8c87cc74a70869000e275892b5004b96db1430f81d2a7d920d159f3024ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page