Array{byte}
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Apr 20 07:12:09 PDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Fri, 20 Apr 2007 at 10:39:04 +0000, Robert Rawlins wrote:
> I've got a function from the dbus bluez api that returns a byte array but i'm a little lost as to how I can extract any useful information from it :-D I'm new to both dbus and python but picking thing up quite nicely.
If you're willing to depend on dbus-python >= 0.80 (recommended):
>>> bytearray = bluez_object.MyMethod(byte_arrays=True)
>>> bytearray
dbus.ByteArray('\x01\x02\x03')
>>> issubclass(dbus.ByteArray, str)
True
See http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#return-values-and-the-byte-arrays-and-utf8-strings-options for details.
If you badly need to be backwards compatible:
>>> list_of_bytes = bluez_object.MyMethod()
>>> list_of_bytes
dbus.Array([dbus.Byte(1), dbus.Byte(2), dbus.Byte(3)], signature='y')
>>> stringified = ''.join(map(chr, list_of_bytes))
>>> stringified
'\x01\x02\x03'
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net
iD8DBQFGKMo5WSc8zVUw7HYRAo82AJ9Qms1WahNm/xAKMFtSpmvM1U04KwCgkMx1
ORIaqAc6TwzLSwWq+l0wHjY=
=eV2a
-----END PGP SIGNATURE-----
More information about the dbus
mailing list