EBCDIC <--> ASCII
Ulrich Eckhardt
eckhardt at satorlaser.com
Thu Dec 4 11:43:34 EST 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:
"abcde\x81\x82\x83\x84"
> 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')
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list