martinjamesevans at gmail.com martinjamesevans at gmail.com
Thu Dec 4 16:37:14 CET 2008

I'm having a problem trying to use the codecs package to aid me in
converting some bytes from EBCDIC into ASCII.

I have some 8bit text that is in mixed format. I extract the bytes
that are coded for EBCDIC and would like to display them correctly.
The bytes that are EBCDIC could values 0-255, I'm only really
interested in the printable portions and could say leave the rest as

I've tried starting with something like this, but I assume it is
expecting the source to be in unicode already?

e.g. (pretend the second half are EBCDIC characters)

sAll = "This bit is ASCII, <this bit ebcdic>"
sSource = sAll[19:]

sEBCDIC = unicode(sSource, 'cp500', 'ignore')
sASCII = sEBCDIC.encode('ascii')

Obviously I could just knock up a 255 character lookup table and do it
myself, I was just trying to be a little more Pythonic and use that
built in table.



More information about the Python-list mailing list