Skip to content

[Suggestion] mapping type? #25

@gnudiff

Description

@gnudiff

Hello and thanks again for implementing this, very useful!
It turns out there are plenty of organisations still using fixed width files, especially older ERP systems.

I was wondering, if you could possibly consider improving your module even further with an additional data type, which would allow for seamless translation of key values between formats, such as frequently are needed? It would allow these conversions happen more transparently and keep the config of data type in one place.

Let us suppose that you have format A, in which certain field ORDER_TYPE can (only) contain certain codes, for example: ["SALE", "PRCH", "XFER"], and you need to convert it to another format B, in which the same codes are called [ "SELL", "BUY", "TRANSFER"]. It seems to me it would be elegant if it were possible to do something like this:

config={
    "ORDER_TYPE": {
      "required" : True,
       "type": "mapping",
       "start_pos": 1,
       "length": 4,
       "values" : dict( SALE="SELL", PRCH="BUY", XFER="TRANSFER")
    }
}

and the effect would be this:

proc=FixedWidth(config)
proc.line="XFER"
proc.data: 
{ 'ORDER_TYPE' : 'TRANSFER'}
proc.line='NONE'
    ValueError: Key not found in mapping data type!'

I would be glad to implement it myself, but I am not certain enough of my Python skills.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions