◐ Shell
clean mode source ↗

Message 64526 - Python tracker

Thomas Heller schrieb:
> Thomas Heller <theller@ctypes.org> added the comment:
> 
>> In the simplest case, convert
>> 
>> import dl
>> libc = dl.open("libc.so.6")
>> iconv = libc.call("iconv_open", "ISO-8859-1", "ISO-8859-2")
>> print(iconv)
>> 
>> to
>> 
>> import ctypes
>> libc = ctypes.CDLL("libc.so.6")
>> iconv = libc.iconv_open("ISO-8859-1", "ISO-8859-2")
>> print(iconv)
>> 

Currently, in py3k, ctypes only passed bytes objects as char*; so
the strings should be translated to bytes literals:

import ctypes
libc = ctypes.CDLL("libc.so.6")
iconv = libc.iconv_open(b"ISO-8859-1", b"ISO-8859-2")
#                       ^              ^
print(iconv)