Steven D'Aprano wrote:

The sample code I've been shown is this:

    pointer_to_obj = id(obj)
    from_deref = ctypes.cast(pointer_to_obj, ctypes.py_object).value
    from_deref is obj  # True

There's no need to use id() or casting to create a ctypes.py_object
instance, you can just call it:

>>> obj = (1,2,3)
>>> obj
(1, 2, 3)
>>> p = ctypes.py_object(obj)
>>> p
py_object((1, 2, 3))
>>> p.value
(1, 2, 3)
>>> p.value is obj
True

--
Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to