I’m a beginner in learning Python.
The version of python I’m using is 3.2.1.1
I’m trying to learn the ctypes by following the tutorial from docs.python.org
in the intereactive prompt,
import ctypes
libc = cdll.msvcrt
printf = libc.printf
printf("%d", 42)
it should return the value 42
but in my case, it returns 0.
So what’s the problem? Thank very much.
Now after I add a >>>from ctypes import cdll, the result became shows this
>>>from ctypes import *
>>>libc = cdll.msvcrt
>>>printf = libc.printf
>>>printf("%d", 42)
Traceback (most recent call last):
File "<stdin>", line1, in <module>
TypeError: 'CDLL' object is not callable
Actually, it should return
2as the number of bytes written tostdout. And it seems to work fine on my Windows installation (after I add the missingfrom ctypes import cdll). Are you using Windows?msvcrtis a Windows only DLL.