[Tutor] trying to translate and ebcidic file

Jerry Hill malaclypse2 at gmail.com
Tue Jun 14 21:42:00 CEST 2011


On Tue, Jun 14, 2011 at 2:40 PM, Prinn, Craig
<Craig.Prinn at bowebellhowell.com> wrote:
> I am looking for a way to translate and ebcidic file to ascii. Is there a
> pre-existing library for this, or do I need to do this from scratch? If from
> scratch and ideas on where to start?

If the file is essentially a text file, I would read the contents in,
decode the resulting bytes to a unicode string, then encode the
unicode string to the encoding of your choice (ascii, utf-8, etc).
You'll also need to know which variant of EBCDIC you're dealing with.
I'm assuming CCSID 500.

Something like this:

input_file = open('my_ebcidic_file', 'rb')
ebcidic_bytes = input_file.read()
unicode_str = ebcidic_bytes.decode('cp500')
ascii_str = unicode_str.encode('ascii')

You can do it in less steps, but that should give you something to start with.

Jerry


More information about the Tutor mailing list