EBCDIC <--> ASCII

martinjamesevans at gmail.com martinjamesevans at gmail.com
Mon Dec 8 09:18:11 CET 2008


On Dec 5, 2:13 pm, Michael Ströder <mich... at stroeder.com> wrote:
> martinjamesev... at gmail.com wrote:
> > On Dec 4, 4:45 pm, Michael Ströder <mich... at stroeder.com> wrote:
> >> martinjamesev... 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.txtlistsit 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.pyhttp://www.stroe...ebcdicatde)
>
> > Thanks for the tables, ebcdicatde.py does look more suitable.
>
> > My problem appears to be that my source is a byte string. In a
> > nutshell I need "\x81\x82\x83\xf1\xf2\xf3" to become "abc123" in a
> > byte string.
>
> Python 2.5.2 (r252:60911, Aug  1 2008, 00:43:38)
>  >>> import ebcdicatde
>  >>> "\x81\x82\x83\xf1\xf2\xf3".decode('ebcdic-at-de').encode('ascii')
> 'abc123'
>  >>>
>
> Ciao, Michael.- Hide quoted text -
>
> - Show quoted text -


Many thanks for all your posts!
Just what I needed.



More information about the Python-list mailing list