EBCDIC <--> ASCII
eckhardt at satorlaser.com
Thu Dec 4 17:43:34 CET 2008
martinjamesevans at gmail.com wrote:
> 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>"
Why pretend? You can use this:
> sSource = sAll[19:]
> sEBCDIC = unicode(sSource, 'cp500', 'ignore')
If you mean this sSource, then no. sSource is treated as byte string here
which is converted to Unicode using 'cp500' as encoding. Note that in
interactive mode, 'print x' will actually convert the string according to
stdout's current encoding (typically ASCII or - I think - Latin 1).
s1 = u'abcde'
s2 = s1.encode('cp500')
s3 = s1.encode('ascii')
s4 = unicode( s2, 'cp500')
s5 = unicode( s3, 'ascii')
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list