问题描述
问:C(pv!= NULL)的想法最直接用Python ctypes表示怎么样?
答:我们当然是应该写类似的东西:
def c_not_null(pv):
return(ctypes.cast(pv,ctypes.c_void_p).value!= None)
是吗?
在医生的工作中,我是一个无能为力的新手,我猜得这么慢......
相关事实如下:
ctypes.c_void_p(0).value ==无
ctypes.c_void_p(0)!= ctypes.c_void_p(0)
奇怪的是你,提前谢谢,Pat LaVarre
也许阅读ctypes教程? (均在2.5文档中和
< http://starship.python.net/crew/theller/ctypes/tutorial.html>)
Gabriel Genellina
Softlab SRL
_________________________________________________
$ b $bPreguntá。 Respondé。 Descubrí。
Todo loquequeríasaber,y lo que ni imaginabas,
$ b $bestáenYahoo! Respuestas(测试版)。
?Probalo ya!
通常指针实例的False布尔值为,所以
''如果pv:....''
应该有效。除了c_void_p,c_char_p和c_wchar_p实例。
Thomas
也许阅读ctypes教程? (均在2.5文档和
< http://starship.python.net/crew/theller/ctypes/tutorial.html>)
实际上,没有。我看到三个答案或零,取决于你喜欢的方式
来计算。
是的平版有助于说清楚,谢谢 - 我可以
更容易获取所有文本匹配的有序列表,而不是
更突出的阴影:
我看到直接讨论如何构造空指针,没有讨论如何测试它们。具体来说:
提示{bool(null_ptr)== False}可以理解为try ==
False,在Pointers中。文本。
提示{(" values",POINTER(c_int))] ... bar.values = None}可以是
读取到例如,在呼叫功能中尝试==无。文本。
提示{if item.name is None}可以读作try is None,在
中访问从dll导出的值 ;文字。
我是一个Python新手,我不知道是不存在
==无。
我想我接下来会深入研究CTypes下面的答案
作者Thomas Heller。
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
Perhaps reading the ctypes tutorial? (both in the 2.5 docs and in
<http://starship.python.net/crew/theller/ctypes/tutorial.html>)
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
?Probalo ya!
http://www.yahoo.com.ar/respuestas
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
Perhaps reading the ctypes tutorial? (both in the 2.5 docs and in
<http://starship.python.net/crew/theller/ctypes/tutorial.html>)
Actually, no. I see three answers or zero, depending on how you like
to count.
Yes that flat edition helps makes this clear, thank you - there I can
more easily grab an ordered list of all matches of text than in the
more prominent shadow:
http://docs.python.org/dev/lib/module-ctypes.html
I see direct discussion only of how to construct null pointers, no
discussion of how to test for them. Specifically:
The hint { bool(null_ptr) == False } could be read to mean try ==
False, in the "Pointers" text.
The hint { ("values", POINTER(c_int))] ... bar.values = None } could be
read to say try == None, in the "Calling functions" text.
The hint { if item.name is None } could be read to say try is None, in
the "Accessing values exported from dlls" text.
I''m such a Python newbie that I didn''t know is None existed alongside
== None.
I guess I''ll next dig into that along with the answer below from CTypes
author Thomas Heller.
这篇关于Python CTypes的翻译(pv!= NULL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!