2024-04-19 08:05:53 发布
网友
我正在使用ctypes和loadingmsvcrt.dllPython中的。在
>>> from ctypes import * >>> libname = 'msvcrt.dll' >>> libc = CDLL(libname) >>> libc.printf("Hello World\n") 12 >>>
为什么它不打印Hello World?在
Hello World
Why doesn't it print Hello World?
在我的Python(ActiveState,2.6)中,当从控制台运行时:
>>> from ctypes import * >>> libc = CDLL('msvcrt.dll') >>> libc.printf("Hello world\n") Hello world 12
{1美元^
Cprintf()函数本身被定义为返回输出的字符数。这是Python在调用libc.printf()时接收到的值。在
printf()
libc.printf()
^{} tutorial提供了有关printf()的输出在Python REPL中不起作用的信息(我的心理调试技能表明您正在空闲地运行Windows GUI)。在
对于其他来这里却不能在python3.x上运行的人来说,原因是that you must pass a bytes string (b"whatever")不是一个常规的Python文本字符串。在
所以这个代码在我的OSX High Sierra上运行得很好:
from ctypes import * libc = CDLL('/usr/lib/libc.dylib') message_string = 'Hello world\n' libc.printf(b"Testing: hello world")
在我的Python(ActiveState,2.6)中,当从控制台运行时:
{1美元^
C
printf()
函数本身被定义为返回输出的字符数。这是Python在调用libc.printf()
时接收到的值。在^{} tutorial 提供了有关
printf()
的输出在Python REPL中不起作用的信息(我的心理调试技能表明您正在空闲地运行Windows GUI)。在对于其他来这里却不能在python3.x上运行的人来说,原因是that you must pass a bytes string (b"whatever")不是一个常规的Python文本字符串。在
所以这个代码在我的OSX High Sierra上运行得很好:
相关问题 更多 >
编程相关推荐