EBCDIC <--> ASCII

Michael Ströder michael at stroeder.com
Thu Dec 4 11:45:05 EST 2008


martinjamesevans at gmail.com wrote:
> I'm having a problem trying to use the codecs package to aid me in
> converting some bytes from EBCDIC into ASCII.

Which EBCDIC variant?

> sEBCDIC = unicode(sSource, 'cp500', 'ignore')

Are you sure CP500 is the EBCDIC variant for the language you want?

http://www.ietf.org/rfc/rfc1345.txt lists it as:

   &charset IBM500
   &rem source: IBM NLS RM Vol2 SE09-8002-01, March 1990
   &alias CP500
   &alias ebcdic-cp-be
   &alias ebcdic-cp-ch

> 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.

It's pythonic to implement a Unicode codec for unknown character tables. 
I've put these two on my web site:

http://www.stroeder.com/pylib/encodings/ebcdicatde.py
http://www.stroeder.com/pylib/encodings/cp273.py (needs ebcdicatde)

Ciao, Michael.



More information about the Python-list mailing list