0

I have a data file that looks similar to:

data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~

The fields are delimited by ~|~ (tilde/pipe/tilde). The row/records are delimited by ~!~.

The goal will be to massage this into an X12 formatted file. I will have many files and many records.. thousands of each.. I just started the project so I am exploring solutions.

I have done a little bit of coding in python so maybe that would work but not sure.

I am looking for suggestions or a library that may contain something to look at at to get started.

4

1 回答 1

1
data = "data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~data1~|~data2~|~data3~!~"

## parse rows
rows = data.split("~!~")

## Parse Columns 
final = [x.split("~|~") for x in rows]
print(final)

结果是:

[['data1', 'data2', 'data3'], ['data1', 'data2', 'data3'], ['data1', 'data2', 'data3'], ['data1', 'data2', 'data3'], ['']]

下一步将转换为 XML。

然后,一旦将其转换为 XML,请使用: https ://pypi.python.org/pypi/pyx12/2.1.1将其转换为 X12

然后就像魔术一样,你应该完成!

于 2015-12-10T05:02:14.960 回答