[Tutor] Converting EBCDIC characters to ASCII
Kent Johnson
kent37 at tds.net
Thu Nov 13 18:51:00 CET 2008
On Thu, Nov 13, 2008 at 11:14 AM, Steve Bricker
<bricker.steve at imonmail.com> wrote:
> I am trying to build an application for work that FTPs a file from an IBM
> mainframe to my Windows desktop then process it. The EBCDIC-to-ASCII
> conversion works nicely (using a BAT file I created) except for three
> packed-decimal data fields (for example, X'0000000000000000014C' is equal to
> integer 14). I am assuming I need to go through this byte-by-byte to
> convert. Is that the best approach, or is there a better way?
Python includes an EBCDIC codec. If s is a byte string containing
EBCDIC characters, then
s.decode('EBCDIC-CP-BE').encode('ascii')
should give you the ASCII equivalent.
Kent
More information about the Tutor
mailing list