Charlie Groves schreef:
> On 10/20/07, Gert-Jan <jython@...> wrote:
>> Suppose you have a pythonlist consisting of unsigned byte-values (0 -
>> 255). And you also know the encoding of this byte-sequence.
>> For single-byte charactersets, this results in an Unicode object:
>> UnicodeText = u''.join([unicode(chr(x), Encoding) for x in lstBytes])
>> But how can I create an Unicode object from a byte-sequence, knowing the
>> sequence is utf-8 or utf-16 encoded?
> ''.join([chr(x) for x in lstBytes]).decode('utf-8') should work,
It works fine, thanks a lot!
> How are you getting a list of bytes in the first place?
I'm a Websphere MQ developer and I'm using Jython to build a small test
program. To access MQ-queuemanagers and -queues I utilize IBM's
com.ibm.mq.jar API. In some cases I have to read the messagedata one
byte at a time (using the MQMessage.readUnsignedByte() method), adding
the unsigned bytevalues to a jythonlist of bytes.
I always know the encoding of a particular bytesequence, so now I'm able
to reconstruct the original messagdata :-)