[Tutor] converting EBCIDIC to ASCII

Marc Tompkins marc.tompkins at gmail.com
Fri Jul 13 21:30:24 CEST 2012


On Thu, Jul 5, 2012 at 9:30 AM, Prinn, Craig <Craig.Prinn at bhemail.com>wrote:

> ** ** ** ** ** **
>
> I am trying to convert an EBCIDIC file to ASCII, when the records are
> fixed length I can convert it fine, I have some files that are coming in as
> variable length records, is there a way to convert the file in Python? I
> tried using no length but then it just reads in to a fixed buffer size and
> I can’t seem to break the records properly
>

I know of only three varieties of variable-length-record files:
-  Delimited - i.e. there's some special character that ends the record,
and (perhaps) a special character that separates fields.  CSV is the
classic example: newlines to separate records, commas to separate fields.

-  Prefixed - there's a previously-agreed schema of record lengths, where
(for example) a record that starts with "A" is 25 characters long; a "B"
record is 136 characters long, etc.

-  Sequential - record types/lengths appear in a previously-agreed order,
such as 25 characters, 136 characters, 45 characters, etc.

For each of these types, the schema may be externally-published, or it may
be encoded in a special record at the beginning of the file - to use an
example near and dear to my own experience, ANSI X12 EDI files all start
with a fixed-length "ISA" record, which among other things contains the
element separator, repetition separator, sub-element separator, and segment
terminator characters in positions 3, 104, 84, and 105.  To read an X12
file, therefore, you read it in - look at positions 3,84, 104, and 105 -
and then use that information to break up the rest of the file into records
and fields.

How you handle variable-length records depends on what kind they are, and
how much you know about them going in.  Python is just a tool for applying
your specialized domain knowledge - by itself, it doesn't know any more
about your particular solution than you do.

If you have more information about the structure of your files, and need
help implementing an algorithm to deal with 'em, let us know!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120713/92559014/attachment.html>


More information about the Tutor mailing list