How to write partial of a buffer which was returned from a C function to a file?
jfong at ms4.hinet.net
Sat Apr 14 21:51:39 EDT 2018
Gregory Ewing at 2018/4/15 PM 08:20 wrote:
> Jach Fong wrote:
>> >>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0))
>> >>> pvoid.contents
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> AttributeError: 'c_void_p' object has no attribute 'contents'
> I think the 'contents' attribute only applies to pointers that are
> pointing at part of another Python object. Your c_void_p instance
> is not that kind of pointer.
> I must say the ctypes documentation is rather confusing when it
> comes to these kinds of details. It doesn't help that the "Pointers
> and Arrays" section is marked as "Not yet written". Does anyone
> have any plans to finish it?
>>> pt = ctypes.cast(buf0, ctypes.POINTER(ctypes.c_void_p))
From the API point of view, I think it's better not to dive into the
ocean of "type" too deeply, especially when foreign language was
involved. You may get totally confused. (unless you want to write code
like in the IOCCC contest:-)
I have to admit that the ctypes' document was written pretty well. Most
of my problems were caused by that I didn't read it thoughtfully:-(
This email has been checked for viruses by Avast antivirus software.
More information about the Python-list