Eryk Sun <eryk...@gmail.com> added the comment:

A simple ctypes type implements a get function that's called when its value is 
returned as an attribute of struct/union, index of an array/pointer, or result 
of a function pointer. For example:

    >>> a = (ctypes.c_char * 1)(97)
    >>> a[0]
    b'a'

    >>> p = ctypes.POINTER(ctypes.c_char)(a)
    >>> p[0]
    b'a'

This behavior can't be changed. However, using a subclass of c_char works 
around it. For example:

    >>> class my_char(ctypes.c_char): pass
    ... 

    >>> a = (my_char * 1)(97)
    >>> a[0]
    <my_char object at 0x7f007dadf640>
    >>> a[0].value
    b'a'

    >>> p = ctypes.POINTER(my_char)(a)
    >>> p[0]
    <my_char object at 0x7f007dadf6c0>
    >>> p[0].value
    b'a'

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45285>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to