Search code examples
pythonpython-2.7glib

Python parsing of a Glib.Variant


I have a python2.7 script which obtains a Glib.Variant e.g.

>>> s
GLib.Variant('a{sa{sv}}', {'connect': {}, 'type': {'login': <'LoginName'>}, 'ipv6': {}, 'ipv4': {}, 'proxy': {}})

How do I parse this to obtain the value of 'login' i.e. 'LoginName' in the above example? (I can find a lot of ref docs online, but no examples to give me a clue to get started). Thanks


Solution

  • The dbus-python tutorial has something on data types. Seems like you have a dictionary (GLib) which maps to a dictionary in Python.

    So the answer should be:

    print s['type']['login']