File: basic_types.rst

package info (click to toggle)
pygobject 3.54.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,864 kB
  • sloc: ansic: 40,281; python: 26,363; sh: 477; makefile: 81; xml: 35; cpp: 1
file content (40 lines) | stat: -rw-r--r-- 906 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
===========
Basic Types
===========

PyGObject will automatically convert between C types and Python types. In
cases where it's appropriate it will use default Python types like :obj:`int`,
:obj:`list`, and :obj:`dict`.


Number Types
------------

All glib integer types get mapped to :obj:`int` and :obj:`float`.
Since the glib integer types are always range limited, conversions from Python
int/long can fail with :class:`OverflowError`:

.. code:: pycon

    >>> GLib.random_int_range(0, 2**31-1)
    1684142898
    >>> GLib.random_int_range(0, 2**31)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OverflowError: 2147483648 not in range -2147483648 to 2147483647
    >>>


Text Types
----------

Text types are mapped to :obj:`str`.


Other Types
-----------

* GList <-> :obj:`list`
* GSList <-> :obj:`list`
* GHashTable <-> :obj:`dict`
* arrays <-> :obj:`list`