Python CTypes translation of (pv != NULL)

Thomas Heller theller at python.net
Tue Sep 26 05:48:52 EDT 2006


p.lavarre at ieee.org schrieb:
> Q: The C idea of (pv != NULL) is said most directly in Python ctypes
> how?
> 
> A: We are of course supposed to write something like:
> 
>         def c_not_null(pv):
>                 return (ctypes.cast(pv, ctypes.c_void_p).value != None)
> 
> Yes?
> 
> Working from the doc, me the clueless newbie, I was slow to guess such
> relevant truths as:
> 
> ctypes.c_void_p(0).value == None
> ctypes.c_void_p(0) != ctypes.c_void_p(0)
> 
> Curiously yours, thanks in advance, Pat LaVarre
> 

Generally pointer instances have a False boolean value, so

'if pv: ....'

should work.  Except for c_void_p, c_char_p and c_wchar_p instances.

Thomas




More information about the Python-list mailing list