Reputation:
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
Upvotes: 3
Views: 1373
Reputation: 34704
Actually, it should return 2
as the number of bytes written to stdout
. And it seems to work fine on my Windows installation (after I add the missing from ctypes import cdll
). Are you using Windows? msvcrt
is a Windows only DLL.
Upvotes: 2