Python and cdll in ctypes. can't use printf

I am starting to learn Python. The python version I'm using is 3.2.1.1 I'm trying to learn ctypes following the tutorial from docs.python.org

in the online invitation

import ctypes
libc = cdll.msvcrt
printf = libc.printf
printf("%d", 42)

it should return 42 but in my case it returns 0. So what is the problem? Many thanks.


Now, after adding →> from ctypes import cdll, the result began to show 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
+3
source share
1 answer

Actually, it should return 2as the number of bytes written to stdout. And it seems to work fine on my Windows installation (after adding the missing one from ctypes import cdll). Do you use windows msvcrtis only a windows dll.

+2
source

All Articles