[Tutor] dbus.Array to string

eryksun eryksun at gmail.com
Mon Aug 12 05:13:07 CEST 2013


On Sun, Aug 11, 2013 at 10:34 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 12/08/13 11:40, eryksun wrote:
>> Typically strings should be unicode. If the byte sequence is Latin-1
>> (including ASCII), you can map unichr() and join the characters with
>> u''.join(); that's equivalent to chr() and ''.join() in 3.x. More
>> generally, decode() the byte string. A simply way that works in 2.6+
>> is to create a bytearray:
>>
>>      >>> bytearray(ssid).decode('latin-1')
>>      u'BigPond679D85'
>
> But, what makes you think that the encoding will be latin-1? If I had to
> guess an encoding, I'd guess UTF-8.

Unicode ordinals in the 8-bit range are Latin-1 (aka ISO-8859-1, i.e.
Basic Latin and Latin-1 Supplement, including C0 and C1 control
codes). You can always decode as Latin-1 without getting a decoding
error. UTF-8 is multibyte and defaults to raising a decoding error if
the sequence isn't valid.

It's up to Amit to figure out what the encoding is. It's D-Bus, so
probably Linux. In that case, UTF-8 is a good guess.


More information about the Tutor mailing list