c - Python ctypes: passing to function with 'const char ** ' argument -
i want pass python list of strings c function expecting const char **. saw question , solution here not seem work me. following sample code:
arglist = ['abc','def'] options = (ctypes.c_char_p * len(arglist))() options[:] = arglist
gives following error:
traceback (most recent call last): file "<interactive input>", line 1, in <module> typeerror: string or integer address expected instead of str instance
what doing wrong?
addendum:
there seems consensus, code should work. here how reproduce problem.
the following 4 lines typed in python command-line illustrate problem.
python 3.2 (r32:88445, feb 20 2011, 21:29:02) [msc v.1500 32 bit (intel)] on win 32 type "help", "copyright", "credits" or "license" more information. >>> ctypes import * >>> arglist = ['abc', 'def'] >>> options = (c_char_p * len(arglist))() >>> options[:] = arglist traceback (most recent call last): file "<stdin>", line 1, in <module> typeerror: string or integer address expected instead of str instance >>>
the sample python code correct.
can paste whole code?
in case, guessing string contains embedded nul bytes, , throws typeerror exception.
hope link helps: http://docs.python.org/c-api/arg.html
Comments
Post a Comment